限制用display:table-cell标记的div的高度?

时间:2013-06-04 00:47:02

标签: css css3

问题:

我需要使用display:table(在父div中)和display:table-cell(在包含的div中)来垂直居中一些内容。这是有效的,除非内容垂直溢出。我想限制高度,以便在有任何垂直溢出时出现滚动条。

小提琴:

http://jsfiddle.net/PTSkR/110/

(请注意,在输出中,尽管我将高度设置为160px,但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;
    }

1 个答案:

答案 0 :(得分:1)

这里是你的小提琴更新,内容包装上有max-height。

.side-study-box {
    background-color: white;
    color: black;
    border: 1px solid #3D6AA2;
    display: table;
    width: 100%;
    border-spacing:1em;
}
.side-box-content {
width: 100%;
  height: ;
   display: table-cell;
}
.text-content-saved {
   max-height:160px;
   overflow:auto;
    padding:5px;
}

http://jsfiddle.net/GCyrillus/6tLAu/

这里的第一个代码是:盒子没有增长 在这里,第二个做第一个,中心内容,如果很少。

.side-study-box {
    background-color: white;
    color: black;
    border: 1px solid #3D6AA2;
    display: table;
    width: 100%;
    border-spacing:1em;
    height:160px;
}
.side-box-content {
width: 100%;
  height: ;
   display: table-cell;
    vertical-align:middle;
}
.text-content-saved {
   max-height:140px;
   overflow:auto;
    padding:5px;
}
相关问题