我正在使用Bootstrap,并尝试创建一个单元格,使其高度和宽度均为其容器的100%。
标题占据该空间的30%,值占据70%。值有上限和下限,每个占据20%,留下60%的空间用于实际值。
HTML:
<div class="container-fluid parameterContainer">
<div class="row paramHead">
<span class="virtAlignFix"></span>
<div class="centerText">
SPO2 (%)
</div>
</div>
<div class="row paramValWrapper">
<div class="row paramLimit">
<span class="virtAlignFix"></span>
<div class="centerText">
200
</div>
</div>
<div class="row paramValue">
<span class="virtAlignFix"></span>
<div class="centerText">
80
</div>
</div>
<div class="row paramLimit">
<span class="virtAlignFix"></span>
<div class="centerText">
40
</div>
</div>
</div>
CSS:
html {
height: 100%;
width: 100%;
}
body {
height: 100%;
width: 100%;
}
.virtAlignFix {
line-height: 100%;
}
.parameterContainer {
height: 100%;
width: 100%;
}
.paramValWrapper {
height: 70%;
width: 100%;
}
.paramLimit {
height: 20%;
width: 100%;
text-align:center
}
.paramHead {
height: 30%;
width: 100%;
text-align:center
}
.paramValue {
height: 80%;
width: 100%;
text-align:center
}
.centerText {
vertical-align:middle;
display:inline-block;
}
我尝试创建的代码片段:
http://jsfiddle.net/WCBjN/1173/编辑:在body和页面中添加了高度百分比。
.parameterContainer
的父元素没有设置任何高度。 - CBroeline-height: 100%
并不能实现你想要的效果,你需要进行更多的研究。关于居中已经讨论过无数遍了。 - CBroe