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:
We're now going to customize the field's CSS.
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:
Inside the CSS file, add the CSS. Here we're going to change the background color to pink:
#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.
Inside each field, choose these settings:
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%:
Now all of the tables in our column should have an equal width:
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.