Miguel Rodríguez does effective software development.

Thumbnails with title on Drupal

This tutorial was tested only on Drupal 7 with Views 3
Requirements:
 
  • Views 3.
  • you should know some CSS basics.
What you'll learn:
 
  • How to customize views using CSS.

What we are looking for

 
In this tutorial we are going to create a list of thumbnails with the title of their respective content, there are three ways to customize views, theming the output, rewriting the result of a field, or adding CSS classes, we have practiced  already how to theme the output and rewrite the result of a field in this tutorial, but this time we will set CSS classes to customize the view and make it look the way that we want to, this is especially useful when the content does not have to have an specific structure.
In order to make this thumbnail list work, we have to add the following code:
 
  1. .thumbnails .left{
  2. position:relative;
  3. display:block;
  4. float:left;
  5. margin-right:5px;
  6. margin-bottom:5px;
  7. border:1px solid black;
  8. }
  9. .thumbnails .left .title{
  10. position:absolute;
  11. bottom:0;
  12. width:100%;
  13. background-color:rgba(00,00,00,0.4);
  14. }
  15. .thumbnails.auto .left .title{
  16. opacity:0;/*optional*/
  17. transition: opacity 2s;/*optional*/
  18. -o-transition: opacity 1s;/*optional*/
  19. -ms-transition: opacity 1s;/*optional*/
  20. -moz-transition: opacity 1s;/*optional*/
  21. -webkit-transition: opacity 1s;/*optional*/
  22. }
  23. .thumbnails.auto .left:hover .title{
  24. opacity:1;/*optional*/
  25. }
This is just going to make every thumbnail float to the left and place every title to the bottom of their respective thumbnails, the "thumbnails" class is described as the container of the thumbnails, the "left" class is going to be assigned to each thumbnail (each thumbnail will float to the left, that why the CSS class is being called like that), and the "title" class will be assigned to the titles (obvious), additionally, there is an extra rule (specified as "auto") that make the title appear and disappear while hovering the thumbnail, of course, you are not forced to use it. the CSS code should be loaded in your theme, keep in mind that those CSS classes are the classes that we are going to assign to the view, so if you change the code, make sure that the CSS classes are matching the assigned CSS classes. the following steps are going to describe the process to make this thumbnail list:
 

Creating the View

 
  • Create a new view as a block with an unformatted list format.
Add a new view (block, Drupal)
Add a new view as a block with an "unformatted list" format.
Attribution: 
 
  • Uncheck all the options in the format settings (this is optional).
Format settings (Drupal)
Format settings (Views)
Attribution: 
 
Uncheck format options (Drupal)
Uncheck all the format options in the format settings (views), it is not mandatory but it is highly encourage.
Attribution: 
 
  • Make sure the view is showing fields and uncheck the options in the fields settings (this is optional too).
Uncheck fields options (Drupal)
Uncheck fields options in the fields settings (it's not mandatory but I would do it anyway).
Attribution: 
 

Adding the Fields

 
  • Apply the proper filters.
Add proper filters (Drupal, Views)
Add the proper filters to the view, defining the content types and required fields such as image fields.
Attribution: 
 
  • Add the image field related with the filters (if applied), define the settings without label, arrange the fields and place it first. Finally, set the style of the images as “thumbnails”, you can define the images with the style that you like, but, I personally encourage to define the images with a square form and a width and height not greater than 350px (I preferred to define the images with an medium style).
Image style (Views, Drupal)
Set the proper style to each image displayed in the view.
Attribution: 
 

Adding CSS code

 
  • We have to add CSS classes to the container, to the fields and the rows in order to make the thumbnail list work, remember that every single CSS class that we are going to assign must match the CSS classes in the code, first we will assign the CSS class to the container by adding “thumbnails” to the “CSS class” option in the advanced section, according to the code above, the CSS class “thumbnails” is surrounding everything else, so this is the CSS class that the container should have. You can also add the CSS class "auto" with "thumbnails" (separated with space) to specify that each title of the thumbnail list should appear only when the user is hovering the image.
CSS Class Container (Views, Drupal)
Set a CSS class to integrate the view with a CSS code.
Attribution: 
 
  • Now, we are going to add a CSS class to the rows, each row is containing an image and a title, we need that each image floats to the left, so we are going to add the CSS class "left".
CSS class rows (Views, Drupal)
Add CSS classes to each row to integrate the view with a CSS code.
Attribution: 
 
  • In conclusion, we are going to add a CSS class to the title field, the proper CSS class for this field is "title".
Title settings (Views, Drupal)
Add to the title a wrapper to set a CSS class in order to integrate it to the CSS code.
Attribution: 
 
Here are the final results:
 
Final thumbnail list
Attribution: 

About me

About the author
Miguel Rodríguez is a freelance developer from Caracas - Venezuela. He is a persistent and goal-oriented person who tries to make the best use of the resources. He is positive, proactive and motivated enough to set a goal with the intention to fulfill it. Find more about him .