Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a Bootstrap thumbnails grid

I have an unknown number of thumbs to display, here is an example of the HTML rendered:

<div class="row-fluid">
        <ul class="thumbnails">
          <li class="span3">
            <a href="#" class="thumbnail">
              <img data-src="holder.js/260x180" alt="260x180" style="width: 260px; height: 180px;" src="mySrc">
            </a>
          </li>
          <li class="span3">
            <a href="#" class="thumbnail">
              <img data-src="holder.js/260x180" alt="260x180" style="width: 260px; height: 180px;" src="mySrc">
            </a>
          </li><li class="span3">
            <a href="#" class="thumbnail">
              <img data-src="holder.js/260x180" alt="260x180" style="width: 260px; height: 180px;" src="mySrc">
            </a>
          </li><li class="span3">
            <a href="#" class="thumbnail">
              <img data-src="holder.js/260x180" alt="260x180" style="width: 260px; height: 180px;" src="mySrc">
            </a>
          </li><li class="span3">
            <a href="#" class="thumbnail">
              <img data-src="holder.js/260x180" alt="260x180" style="width: 260px; height: 180px;" src="mySrc">
            </a>
          </li>
          <li class="span3">
            <a href="#" class="thumbnail">
              <img data-src="holder.js/260x180" alt="260x180" style="width: 260px; height: 180px;" src="mySrc">
            </a>
          </li>
          <li class="span3">
            <a href="#" class="thumbnail">
              <img data-src="holder.js/260x180" alt="260x180" style="width: 260px; height: 180px;" src="mySrc">
            </a>
          </li>
        </ul>
      </div>

Here is the result: screen shot

Question : Since I build the UI dynamically, how can I avoid the margin on the second row without creating another <div class="row-fluid">

Update IE8 solution is required

like image 523
Shlomi Schwartz Avatar asked Mar 04 '13 16:03

Shlomi Schwartz


People also ask

How do I create a thumbnail in Bootstrap?

Step 1: Include Bootstrap and jQuery CDN into the <head> tag before all other stylesheets to load our CSS. Step 2: Add <div> tag in the HTML body with class row. In that <div> create four div sections to create four images. Step 3: Add “col-sm-6” and “col-md-3” to four div sections which creates webpage responsive.

Which Bootstrap class will you use to make a thumbnail image?

img-thumbnail class. Image Thumbnails: In Bootstrap 4, the image thumbnail is a border surrounded by the image. To create this image thumbnail you can use the . img-thumbnail class.

What is a thumbnail layout?

A thumbnail also means a small and approximate version of a full-size image or brochure layout as a preliminary design step. This is also referred to as a preview image and is a smaller version of the original image.

What CSS property is used to create thumbnails?

To create thumbnail image with CSS, use the border property.


1 Answers

Assuming the width won't change of the LI's parent using :nth-child(4n) should work to target the x element.

.row-fluid li:nth-child(4n) {
    margin: 10px;
    padding: 0;
 }

See the spec for details on how to write formulas for :nth-child().

A very very basic Fiddle displaying it working.

Update

To work with IE8 just use jQuery (assuming you're using it)

$('.row-fluid li:nth-child(4n)').css({'margin':'10px'});

I do believe that should do the trick.

like image 89
Jamie Hutber Avatar answered Sep 21 '22 19:09

Jamie Hutber