【问题标题】:Bootstrap Grid Columns Not AligningBootstrap 网格列未对齐
【发布时间】:2017-08-02 10:18:23
【问题描述】:

我正在尝试在引导程序中创建一个响应式网格,页面上有四个产品(有四列)。我希望每个产品的盒子在页面上完美排列。当标题的文本行数不同时,我遇到了问题。可以看到下面的问题(注意我还没有添加第四个产品)。

https://ibb.co/kE1UH5

这是我的 HTML 代码

 <div class="container bg">
 <!-- Three columns of text below the carousel -->
      <div class="row">
        {% for deal in deals %}
        <div class="col-xs-12 col-sm-6 col-md-3 rwrapper">
          <div class="rlisting">
        <div class="col-md-12 nopad hover11">
            <figure><img src="{{ deal.image.url }}" class="img-responsive" style="width:250px;height:250px;margin:20px"></figure>
        </div>
        <div class="col-md-12 nopad">
          <h5>{{ deal.retailer}}</h5>
           <h3>{{ deal.title}}</h3>
            <h3><strong>{{deal.price}}</strong><h3>
           <div class="rfooter">
             <i class="fa fa-phone-square"></i><a href="{{deal.link}}" role="button" class="btn btn-success">See Deal</a>
           </div>
        </div>
      </div>
    </div>
{% endfor %}

 </div>
</div>

这里还有 CSS:

.bg{background-color: #dfdfdf;}
.rwrapper{padding: 1px;}
.rlisting{background-color: #fff;overflow: hidden;}
.rlisting img{width: 100%}
.nopad{padding:0;}
.rfooter{width: 50%;}
.rlisting h5,.rlisting p{padding:0 15px; font-style:italic;}
.rlisting h3,.rlisting p{padding:0 15px;}

/* Opacity #1 */
.hover11 figure img {
    opacity: 1;
    -webkit-transition: .3s ease-in-out;
    transition: .3s ease-in-out;
}
.hover11 figure:hover img {
    opacity: .5;
}

.column {
    margin: 15px 15px 0;
    padding: 0;
}
.column:last-child {
    padding-bottom: 60px;
}
.column::after {
    content: '';
    clear: both;
    display: block;
}
.column div {
    position: relative;
    float: left;
    width: 300px;
    height: 200px;
    margin: 0 0 0 25px;
    padding: 0;
}
.column div:first-child {
    margin-left: 0;
}
.column div span {
    position: absolute;
    bottom: -20px;
    left: 0;
    z-index: -1;
    display: block;
    width: 300px;
    margin: 0;
    padding: 0;
    color: #444;
    font-size: 18px;
    text-decoration: none;
    text-align: center;
    -webkit-transition: .3s ease-in-out;
    transition: .3s ease-in-out;
    opacity: 0;
}
figure {
    margin: 0;
    height: 250px;
    width: 250px;
    padding: 0;
    background: #fff;
    overflow: hidden;
}
figure:hover+span {
    bottom: -36px;
    opacity: 1;
}

.navbar {
    margin-bottom:-1px;
    border-radius:0;
}
#submenu {
    background-color: #e7e7e7;
    margin-bottom:20px;
    min-height:0;
}
.navbar-nav{margin:0}
.collapsing {
    display:none;
}
.jumbotron {
    margin-top: 50px;
  }

 .nav-2{
  position:fixed;
  top:50px;
  left:0px;
  width:100%;
  background:#fff;
  padding-top:0px;
  padding-bottom:0px;
}

.container-2{margin-top:120px}

【问题讨论】:

    标签: html css twitter-bootstrap


    【解决方案1】:

    我会使用scss 而不是css 来简化此操作,并将标题的高度设置为您希望显示的最大行数的倍数。

    $line-height: 20px;
    $line-count: 3;    //Example of 3 lines
    .title {
        line-height: $line-height;
        height: $line-count * $line-height;
    }
    

    然后,您还应该将显示的文本长度限制在不超过 3 行的合理范围内(如果需要,还可以添加省略号)。

    这当然也可以使用css 来完成,并在本例中将其设置为 60px。

    【讨论】:

    • 感谢这似乎起到了作用——在 CSS 中使用了 60 像素的高度和 20 像素的行高。唯一的问题是我的行之间没有太多间距。我尝试增加高度但没有帮助。有什么想法吗?
    猜你喜欢
    • 2022-11-12
    • 1970-01-01
    • 2015-06-14
    • 2018-04-14
    • 2014-12-25
    • 2017-03-10
    • 2014-10-02
    相关资源
    最近更新 更多