问题:
我需要使用display:table
(在父 div 中)和display:table-cell
(在包含的 div 中)将某些内容垂直居中。除非内容垂直溢出,否则这是有效的。我想限制高度,以便在有任何垂直溢出时出现滚动条。
小提琴:
http://jsfiddle.net/PTSkR/110/
(请注意,在输出中,尽管我将高度设置为 160 像素,但 div 仍垂直扩展)
CSS:
side-study-box {
background-color: white;
color: black;
border: 1px solid #3D6AA2;
text-align: center;
height: 160px !important;
display: table !important;
margin: 0px !important;
margin-left: -1px !important;
position: relative;
overflow-y: scroll;
width: 100%;
}
.side-study-box .side-box-content {
width: calc(100%);
height: 160px !important;
float: right;
display: table;
overflow-y: scroll;
}
.side-study-box .text-content-saved {
width: 100% !important;
font-size: 24px;
display: table-cell;
vertical-align: middle;
text-align: center;
height: 160px !important;
max-height: 160px !important;
background-color: white;
padding: 0px !important;
margin: 0px !important;
font-family: "Segoe UI", Frutiger, "Frutiger Linotype", "Dejavu Sans", "Helvetica Neue", Arial, sans-serif;
border: 0px !important;
overflow-y: scroll;
}