我在一行中有3个Div-Container。由于内容的原因,每个人都有不同的身高。我想设置背景颜色,但是颜色应达到父级Div(行)的底部。我所有的尝试都失败了,我不会得到与div相同的高度。
<div class="row">
<div class="col-md-7">Test</test>
<div class="col-md-2">Test</test>
<div class="col-md-3">Test</test>
</div>
有了桌子,这很容易,但是那不是最先进的...
如果我不支持响应式布局,那么css样式将是什么呢?
答案 0 :(得分:1)
对于 Bootstrap 3 版本,您可以使用以下方法将 md + 屏幕设备(width >= 992px
)设置为固定高度:
@media(min-width:992px) {
.fixed-md-height {
height: 150px;
}
.h-100 {
height: 100%;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<div class="container-fluid">
<div class="row fixed-md-height">
<div class="col-md-7 h-100 bg-danger">Test</div>
<div class="col-md-2 h-100 bg-primary">Test</div>
<div class="col-md-3 h-100 bg-warning">Test</div>
</div>
</div>
在 Bootsrap 4 上已经存在一个内置类h-100
,但是 md 断点更改为width >= 768px
。因此,方法将是这样的:
@media(min-width:768px) {
.fixed-md-height {
height: 150px;
}
}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<div class="container-fluid">
<div class="row fixed-md-height">
<div class="col-md-7 h-100 bg-danger">Test</div>
<div class="col-md-2 h-100 bg-primary">Test</div>
<div class="col-md-3 h-100 bg-warning">Test</div>
</div>
</div>