Hướng dẫn chèn CSS Style vào trong Drupal 7 Views

Hướng dẫn chèn CSS Style vào trong Drupal 7 Views

This week one of our OSTraining members was working with the Views module.

They were able to create views, but weren't sure how to improve their design.

In this tutorial, we're going to show you how to apply CSS to your views so you can add both color and width.

#1: Adding CSS color to a column

Here is a very standard Drupal table that I've created. I'm going to add color to one of the columns, the Title:

media_1400612860811.png

  • In editing the view, click on the field you want to edit:

media_1400614862458.png

  • Click Style Settings and you'll see options for adding HTML and CSS to the field:

media_1400613075900.png

We're now going to customize the field's CSS.

  • Click "Create a CSS class".

  • Enter a new CSS class name. In this example, I used "views-title":

media_1400613106912.png

Now, we're going to go to our theme's files to add the CSS.

Many themes use style.css for their main CSS, but your theme maybe different:

media_1400613389402.png

Inside the CSS file, add the CSS. Here we're going to change the background color to pink:

media_1400613522551.png

  • Save the CSS file.

  • Clear the cache on your Drupal site via Configuration > Performance.

  • Your CSS changes should now apply to the Title column:

media_1400615339320.png

#2: Adding width to Views columns

Let's customize our table in a different way. Notice that one column, "Type" is very narrow. Let's even out the width of our columns.

media_1400613573769.png

Inside each field, choose these settings:

  • Click "Customize label HTML".

  • Click "CSS class".

  • Enter "views-table-width" into the CSS class box:

media_1400614403315.png

I repeated that process for all four fields in the view.

As before, we can now add the CSS we need to our theme. In this case, we'll give each column a width of 25%:

media_1400613992021.png

Now all of the tables in our column should have an equal width:

media_1400614529917.png

Note: CSS does not apply to previews

One important thing to note is that your CSS will not apply inside the Views editing screen. This can sometimes make it a little harder to test changes accurately.

If you are working on changes to a live view, it may be worth making a clone of that view or working on a test site.

media_1400614449039.png

Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Hướng dẫn tạo custom search cho custom post type trong wordpress

Hướng dẫn tạo custom search cho custom post type trong wordpress

Have you ever worked on a WordPress site that has a lot of custom post types? Well as-is WordPress search is a disaster which is why many bloggers use Google custom search.

Thông tin từ DrupalCon Amsterdam cho Frontend developers

Thông tin từ DrupalCon Amsterdam cho Frontend developers

DrupalCon Amsterdam is less than one month away! I'm excited to meet up with all the Frontend developers who are coming to learn new things from each other.

SEO

Những yếu tố xếp hạng sẽ giảm ‘trọng lượng’ trong năm 2012

Có lẽ năm vừa qua SEO đã có 1 chuyển biến khá lớn khi bắt đầu chiến dịch Panda và các mirror mở rộng tầm ảnh hưởng. Trong đó các yếu tố SEO có những thay đổi và Google dần trở nên thông minh hơn khi thay đổi độ mạnh và yếu của các yếu tố này. Đặc biệt những yếu tố sau đây nó đã dần mất ưu thế và tất nhiên bạn cũng nên xem lại những yếu tố này để không phải quá chú trọng vào nó:

Công ty diệt chuột T&C

 

Diet con trung