Can't figure out how to use Bootstrap thumbnail component

邮差的信 提交于 2019-12-09 08:41:02

问题


I'm trying to use Bootstrap's thumbnail component to display a list of product categories with thumbnail images. I want users to click the thumbnails to go to the category.

The documentation on the Bootstrap website provides this basic markup:

<ul class="thumbnails">
    <li class="span4"> 
        <a href="#" class="thumbnail">
            <img data-src="holder.js/300x200" alt="">
        </a>
    </li>
    ...
</ul>

I've Googled for information about holder.js, found the official holder.js page, downloaded the zip version, put the files in my site's js folder and linked to the holder.js file with a script tag in my HTML.

But how/where in the markup do I specify what image files to use?

I also need to include a category name under each image, probably with a span or h4 tag. This would need to form part of the clickable block.

UPDATE: Just to clarify, it's really only the styling aspects of the thumbnail component that I want to utilise. So perhaps I can achieve this with the thumbnails component and associated HTML markup, and leave out holder.js altogether?

This is the kind of HTML mark-up I would like to use:

<ul class="thumbnails">
    <li class="span4">
        <a href="/category-name/" class="thumbnail">
            <img src="/assets/images/filename.jpg" alt="">
            <span>Category name</span>
        </a>
    </li>
    ...
</ul>

回答1:


Holder.js is just image placeholder framework based on javascript and inline images. It is used by bootstrap to create sample images. There is no need in this library on production. So instead of using data-src attribute and holder.js library you should use src attribute and markup like:

<ul class="thumbnails">
    <li class="span4">
        <a class="thumbnail" href="#">
            <img src="/image/path.jpg" alt="My Image" />                
            <span class="caption">This is my image</span>
        </a>
    </li>
</ul>

You can also need to disable text underline in image caption. Just use css:

a.thumbnail:hover {
    text-decoration: none;
}

Example: http://jsfiddle.net/M3fpA/46/



来源:https://stackoverflow.com/questions/16017532/cant-figure-out-how-to-use-bootstrap-thumbnail-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!