html - 如何在 Bootstrap 中按百分比排列 div 的高度,没有滚动条

标签 html css twitter-bootstrap responsive-design

我想制作一个响应式的内容框。我可以按百分比设置 Div 的宽度(例如:30%、50%)。但是当我以百分比设置高度时,它不起作用。 我想在页面的特定 % 中制作页面的 3 个 div。

.top
{
	height:250px;
     /*height:28%;*/
	background-color:#dad8c3;
	width:100%;
	
}
.body_part{
	width:100%;
	background-color:#9CC;
	
	height:560px;
    /*height:60%;*/
	   background: -webkit-linear-gradient(-90deg,#e4e0dd,white,#e4e0dd ); /* For Safari 5.1 to 6.0 */
    background: -o-linear-gradient(-90deg,#e4e0dd,white,#e4e0dd); /* For Opera 11.1 to 12.0 */
    background: -moz-linear-gradient(-90deg,#e4e0dd,white, #e4e0dd); /* For Firefox 3.6 to 15 */
    background: linear-gradient(-90deg,#e4e0dd,white, #e4e0dd); /* Standard syntax (must be last) */
	
}
.footer_part{

	background-color:#6c5067;
	width:100%;
    height:97px;
	/*height:12% !important;*/
	
}
html,body{
	background-image:url(../images/moment%20a.jpg);
	height:100%;

}
<div class="row">
  <div class="col-lg-12 top">
  <div class="container"></div>
   </div>
   </div>
   <div class="row">
   <div class="col-lg-12 body_part">
   <div class="container"></div>
   </div>
  </div>
  <div class="row">
  <div class=" col-lg-12 footer_part">
  <div class="container"></div>
  </div>
  </div>

最佳答案

您可以使用 viewport percentage这样做的单位:

html,
body, body > div {
  padding:0;
  margin:0;
}

.top {
  height: 28vh;
  background-color: #dad8c3;
}
.body_part{
  background-color: #9CC;
  height: 60vh;
  background: -webkit-linear-gradient(-90deg, #e4e0dd, white, #e4e0dd);
  /* For Safari 5.1 to 6.0 */
  background: -o-linear-gradient(-90deg, #e4e0dd, white, #e4e0dd);
  /* For Opera 11.1 to 12.0 */
  background: -moz-linear-gradient(-90deg, #e4e0dd, white, #e4e0dd);
  /* For Firefox 3.6 to 15 */
  background: linear-gradient(-90deg, #e4e0dd, white, #e4e0dd);
  /* Standard syntax (must be last) */
}
.footer_part {
  background-color: #6c5067;
  height:12vh;
}
<div class="row">
  <div class="col-lg-12 top">
    <div class="container"></div>
  </div>
</div>
<div class="row">
  <div class="col-lg-12 body_part">
    <div class="container"></div>
  </div>
</div>
<div class="row">
  <div class=" col-lg-12 footer_part">
    <div class="container"></div>
  </div>
</div>

关于html - 如何在 Bootstrap 中按百分比排列 div 的高度,没有滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28826388/

相关文章:

css - 阻止 anchor 使字体很棒的图标变蓝?

javascript - angularjs ui-select禁用下拉列表并使其只能搜索

javascript - 使用 jQuery 确定视口(viewport)大小

javascript - jQuery .animate() - 不工作

html - 我如何平均间隔 css 网格列?

javascript - Jquery 不激活表元素的 onClick

javascript - 如何在点击链接时打开产品标签?

css - 选择具有不同类型 child 的最后一个 child

css - 如何更改 Bootstrap 链接的颜色

css - Bootstrap 交换网格跨度