css - 如何使用 bootstrap 使我的 DIV 出现在彼此下方

标签 css twitter-bootstrap-3

我有以下内容: Pic 1 我想要这些结果: Pic 2

我正在使用 bootsrap 3

这是我的 HTML 和 CSS 代码:

.product-item {
    /*height: 425px;*/
    padding-left: 5px;
    padding-right: 5px;
    text-align: center;
    /*margin: 0 -10px;*/
    display: inline-block;
}
.product-item_inner {
    background-color: yellow;
    /*display: inline-block;*/
    margin-bottom: 20px;
    /*min-height: 522px;*/
    padding: 10px;

    width:auto; height:auto;
}
a.s_thumb img {
    margin-left: auto;
    margin-right: auto;
    /*max-width: 270px;*/
}
div.product-item h3 {
    font-size: 15px;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- Google Fonts !! -->
    <link href='https://fonts.googleapis.com/css?family=Roboto:300' rel='stylesheet' type='text/css'>

    <!-- Already inserted !! -->
    <link href="css/font-awesome.css" rel="stylesheet">


</head>
<body>


<div class="container">
    <div class="row">
        <div class="col-lg-4 col-md-6 col-sm-6 col-xs-12 product-item">
            <div class="product-item_inner text-center">
                <a class="s_thumb" href="#">
                    <img width="280" height="140" src="http://lorempixel.com/280/140/" class="img-responsive"
                         alt="title example">
                </a>
                <h3><a href="#">Lorem ipsum 1</a>
                </h3>

                <p class="s_price">250,00 € </p>


            </div>
        </div>


        <div class="col-lg-4 col-md-6 col-sm-6 col-xs-12 product-item">
            <div class="product-item_inner text-center">
                <a class="s_thumb" href="#">
                    <img width="280" height="240" src="http://lorempixel.com/280/240/" class="img-responsive"
                         alt="title example">
                </a>
                <h3><a href="#">Lorem ipsum 2</a>
                </h3>

                <p class="s_price">250,00 € </p>

            </div>
        </div>

        <div class="col-lg-4 col-md-6 col-sm-6 col-xs-12 product-item">
            <div class="product-item_inner text-center">
                <a class="s_thumb" href="#">
                    <img width="280" height="70" src="http://lorempixel.com/280/70/" class="img-responsive"
                         alt="title example">
                </a>
                <h3><a href="#">Lorem ipsum 3</a>
                </h3>

                <p class="s_price">250,00 € </p>

            </div>
        </div>

        <div class="col-lg-4 col-md-6 col-sm-6 col-xs-12 product-item">
            <div class="product-item_inner text-center">
                <a class="s_thumb" href="#">
                    <img width="280" height="140" src="http://lorempixel.com/280/140/" class="img-responsive"
                         alt="title example">
                </a>
                <h3><a href="#">Lorem ipsum 4</a>
                </h3>

                <p class="s_price">250,00 € </p>

            </div>
        </div>

        <div class="col-lg-4 col-md-6 col-sm-6 col-xs-12 product-item">
            <div class="product-item_inner text-center">
                <a class="s_thumb" href="#">
                    <img width="280" height="150" src="http://lorempixel.com/280/150/" class="img-responsive"
                         alt="title example">
                </a>
                <h3><a href="#">Lorem ipsum 5</a>
                </h3>

                <p class="s_price">250,00 € </p>

            </div>
        </div>

        <div class="col-lg-4 col-md-6 col-sm-6 col-xs-12 product-item">
            <div class="product-item_inner text-center">
                <a class="s_thumb" href="#">
                    <img width="280" height="205" src="http://lorempixel.com/280/205/" class="img-responsive"
                         alt="title example">
                </a>
                <h3><a href="#">Lorem ipsum 6</a>
                </h3>

                <p class="s_price">250,00 € </p>

            </div>
        </div>


    </div>
</div>


</div>


<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/scripts.js"></script>
</body>
</html>

最佳答案

您可以使用 CSS3 列。

要做到这一点,去掉所有那些 col-xx div 并将 product-item 类分配给 div.

然后剩下的就是将此样式添加到您的 product-item:

.product-item { -webkit-column-count: 3; column-count: 3; }

演示 fiddle :http://jsfiddle.net/abhitalks/o8mksrc2/1/

演示片段:

.product-item { -webkit-column-count: 3; column-count: 3; }
.product-item_inner {
    background-color: yellow;
    margin-bottom: 20px; padding: 10px;
    width:auto; height:auto;
    -webkit-column-break-inside: avoid;
}
a.s_thumb img { margin-left: auto; margin-right: auto; }
div.product-item h3 { font-size: 15px; }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
    <div class="row product-item">
        <div class="product-item_inner text-center">
            <a class="s_thumb" href="#">
                <img width="280" height="140" src="http://lorempixel.com/280/140/" 
                     class="img-responsive" alt="title example" />
            </a>
            <h3><a href="#">Lorem ipsum 1</a></h3>
            <p class="s_price">250,00 € </p>
        </div>        
        <div class="product-item_inner text-center">
            <a class="s_thumb" href="#">
                <img width="280" height="240" src="http://lorempixel.com/280/240/" 
                     class="img-responsive" alt="title example" />
            </a>
            <h3><a href="#">Lorem ipsum 2</a> </h3>
            <p class="s_price">250,00 € </p>
        </div>
        <div class="product-item_inner text-center">
            <a class="s_thumb" href="#">
                <img width="280" height="70" src="http://lorempixel.com/280/70/" 
                     class="img-responsive" alt="title example" />
            </a>
            <h3><a href="#">Lorem ipsum 3</a></h3>
            <p class="s_price">250,00 € </p>
        </div>        
        <div class="product-item_inner text-center">
            <a class="s_thumb" href="#">
                <img width="280" height="140" src="http://lorempixel.com/280/140/" 
                     class="img-responsive" alt="title example" />
            </a>
            <h3><a href="#">Lorem ipsum 4</a></h3>
            <p class="s_price">250,00 € </p>
        </div>        
        <div class="product-item_inner text-center">
            <a class="s_thumb" href="#">
                <img width="280" height="150" src="http://lorempixel.com/280/150/" 
                     class="img-responsive" alt="title example" />
            </a>
            <h3><a href="#">Lorem ipsum 5</a></h3>
            <p class="s_price">250,00 € </p>
        </div>        
        <div class="product-item_inner text-center">
            <a class="s_thumb" href="#">
                <img width="280" height="205" src="http://lorempixel.com/280/205/" 
                     class="img-responsive" alt="title example" />
            </a>
            <h3><a href="#">Lorem ipsum 6</a></h3>
            <p class="s_price">250,00 € </p>
        </div>        
    </div>
</div>
    
    

关于css - 如何使用 bootstrap 使我的 DIV 出现在彼此下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32970046/

相关文章:

jquery-selectors - bootstrap 3 selectpicker input-lg 被覆盖

javascript - bootstrap多模态结构

html - 100% 时 div 元素的高度与父元素的高度不匹配

html - 定位带有内联文本的图像

html - 部分宽度边框

css - 使用 CSS 显示两种不同的渐变作为背景?

html - 像在歌曲簿中一样自定义上标

html - Div 没有排队

php - 如何在 wordpress 导航中不影响子项的情况下突出显示处于事件状态的父项?

html - 我的网站的性能报告