Drupal 8 Tutorial : Clickable Responsive Grid With Views (Article + Video)

Submitted by TheMain on Tue, 10/18/2016 - 18:57

How to create a responsive, clickable grid with views.

Bootstrap Subtheme

Create Image Style

  • Go to admin/config/media/image-styles
  • Create an image style with Scale and crop effect 300×200

Create the View

  • Create an Unformatted list View Block with Image, Title, Path and Custom Text fields:

  • Image field settings:

 

  • Title field settings:

 

 

I added p tags around the title with rewrite results so we can target it better. I tried to add them with the STYLE SETTINGS first, but the trimming option removed them.

  • Path field settings:

  • Global: Custom Text settings:

  • Edit FORMAT: Settings and add col-md-4 class to rows:

col-md-4 class creates 3 columns.

  • Go to the view Advanced: CSS class settings and add a container-fluid class to the view:

CSS (LESS)

.view-responsive-grid {
  margin-top: 1em;
  img {
    width: 100%;
    border: 3px solid #eee;
    padding: 3px;
    border-radius: 5px;
  }
  img:hover {
    border-color: #ddd;
  }
  a {
    color: #fff;
    text-decoration: none;
  }
  p {
    display: inline;
    position: relative;
    bottom: 60px;
    left: 6px;
    background: rgba(17, 17, 17, .5);
    color: #fff;
    padding: 0.5em 0.7em;
  }
}

Place the Block

  • Go to admin/structure/block and Place Block above the Main page content.
  • Block settings:

Result

Now we have the grid showing only in the front page:

Links

http://www.wdtutorials.com/drupal/theming/bootstrap-1-subtheme-cdn-drupa...

Posted by Samuli Natri on 18 October 2016