【发布时间】:2015-10-26 07:52:08
【问题描述】:
http://www.bootply.com/somVIZEXxC# 这是我网站的引导程序,基本上我希望 cols col-lg-6 具有相同的高度,以便我在其中的图像是均匀的,目前,一个图像延伸到另一个图像下方一个。
【问题讨论】:
-
我试过那个解决方案,它对我不起作用
标签: html css twitter-bootstrap
http://www.bootply.com/somVIZEXxC# 这是我网站的引导程序,基本上我希望 cols col-lg-6 具有相同的高度,以便我在其中的图像是均匀的,目前,一个图像延伸到另一个图像下方一个。
【问题讨论】:
标签: html css twitter-bootstrap
内容应放在列中,并且只能列 行的直接子代
所以从.row 中取出h1 并将.row-eq-height 类设置为.row,如下所示:
.row-eq-height{
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
<div class="row row-eq-height"></div>
这里有完整的信息http://getbootstrap.com.vn/examples/equal-height-columns/
这里有一个最小的 sn-p 来说明:
.row-eq-height{
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<h1 class="text-center"> Where do we cater to? </h1>
<div class="row row-eq-height">
<div class="col-xs-6">
<img src="http://i.stack.imgur.com/gijdH.jpg?s=328&g=1" class="img-responsive">
</div>
<div class="col-xs-6" style="background: blueviolet">
<img src="http://orig00.deviantart.net/0cbb/f/2013/107/3/a/lnd_small_bmp_64x64_by_shadowblitz-d620m47.jpg" class="img-responsive">
</div>
</div>
就像我说的我不知道你的img的限制(高度,如果可以是背景等)这里有一些提示来实现你想要的:
从row 中删除margin 和从col- 中的填充,将width: 100% 添加到您的图像中,如下所示:
.row-eq-height{
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
margin: 0;
}
.row-eq-height [class*="col-"]{
padding: 0;
}
.row-eq-height img{
width: 100%;
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<h1 class="text-center"> Where do we cater to? </h1>
<div class="row row-eq-height">
<div class="col-xs-6">
<img src="http://i.stack.imgur.com/gijdH.jpg?s=328&g=1" class="img-responsive">
</div>
<div class="col-xs-6" style="background: blueviolet">
<img src="http://orig00.deviantart.net/0cbb/f/2013/107/3/a/lnd_small_bmp_64x64_by_shadowblitz-d620m47.jpg" class="img-responsive">
</div>
</div>
如果图像可以是背景,您可以定义一个特定的比例高度,您可以使用 padding-top,比如说 4:3,即 3 * 100 / 4 = 75 = padding-top
所以你可以这样做:
.row-eq-height{
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
margin: 0;
}
.row-eq-height [class*="col-"]{
padding: 0;
}
.img-container{
background-size: cover;
padding-top: 75%; /*you can change it to obtain a desired height*/
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<h1 class="text-center"> Where do we cater to? </h1>
<div class="row row-eq-height">
<div class="col-xs-6">
<div class="img-container" style="background-image: url(http://i.stack.imgur.com/gijdH.jpg?s=328&g=1)"></div>
</div>
<div class="col-xs-6">
<div class="img-container" style="background-image: url(http://orig00.deviantart.net/0cbb/f/2013/107/3/a/lnd_small_bmp_64x64_by_shadowblitz-d620m47.jpg)"></div>
</div>
</div>
【讨论】:
col- 具有相同的高度,让我知道这是否适合你。
只需将“equal-heights”类添加到父列
$('.equal-heights').each(function(){
var highestBox = 0;
$(this).children('[class*="col-"]').each(function(index, el){
if( $(el).height() > highestBox ) highestBox = $(el).height();
});
$(this).children('[class*="col-"]').css('height',highestBox);
});
html 会是这样的......
<div class="row equal-heights">
<div class="col-md-4">...</div>
<div class="col-md-4">...</div>
<div class="col-md-4">...</div>
</div>
【讨论】:
试着拿出你的
<h1 class="text-center"> Where do we cater to? </h1>
因为一个“行”意味着加起来为 12。现在,您在行中有这个 h1 以及两个 col-lg-6,它们应该在自己的一行中(6+6= 12).
h1 应该与它自己的 col-lg-12 或任何你想要的东西在它自己的行中。
【讨论】:
您是否尝试过使用max-height:?
这是你代码的一个分支http://www.bootply.com/wVSqmPKERL
在列中添加了另一行并添加了 height-fix 的类,它只是添加了
max-height 属性,您可以将其设置为您需要的任何内容。
编辑
如果图像太小,您也可以将其与 min-height 结合使用
【讨论】:
height-fix 的原因,所以你只是扩展列类而不是直接编辑它,是的,使用 px 继承了一些关于它的信息css-tricks.com/almanac/properties/m/max-height
max-height设置为图片所在的列
这是一个带有图像的响应式网格。图像容器具有相同的高度,图像本身垂直居中;
.grid {
margin-top: 25px;
display: flex;
flex-wrap: wrap;
}
.grid>[class*='col-'] {
display: flex;
flex-direction: column;
align-items: stretch;
margin-bottom: 15px;
}
.grid img {
margin: auto 0;
}
@media (max-width: 767px) {
.container {
max-width: 100%;
}
}
@media (max-width: 575px) {
.container {
max-width: 100%;
padding-left: 0;
padding-right: 0;
}
.posts-grid>[class*='col-'] {
padding-left: 5px;
padding-right: 5px;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="grid">
<div class="col-sx-6 col-md-4 col-lg-2">
<img src="http://placehold.it/350x300" class="img-responsive">
</div>
<div class="col-sx-6 col-md-4 col-lg-2">
<img src="http://placehold.it/350x450" class="img-responsive">
</div>
</div>
</div>
【讨论】: