是否可以将内容插入DIV但是DIV的大小保持不变?

时间:2017-04-04 11:58:41

标签: html css css3

我有三个DIV元素填充视口。所有三个DIV都有position: absoluteleft: 0pxwidth: 100%

最高DIV有height: 10%,中间DIV有height: 88%,最低DIV有height: 2%

例如,有没有办法让我在顶部DIV中插入文字并让它保持在10%的高度?因为10%的大小足以包含没有DIV增长的文本......但是无论如何DIV都会增长。

HTML:

<html>
<head>
    <link rel='stylesheet' href='css/style.css' />
</head>
<body>

    <div id="bodyWrap">
        <div id="header" class="box">
        a
        </div>
        <div id="mid"  class="box">
        a
        </div>
        <div id="footer"  class="box">
        a
        </div>
    </div>

</body>
</html>

CSS:

@font-face{ 
    font-family: gab; 
    src: url('gabriola.ttf');
}

#bodyWrap
{
    /*If ever necessary.*/
    text-align: center;
    font-family: gab;
}

.box
{
    background-color: rgb(216, 179, 126);
    position: absolute;
    width: 100%;
    left: 0px;
}

#header
{
    height: 10%;
    top: 0px;
}

#mid
{
    height: 88%;
    top: 10%;
}

#footer
{
    height: 2%;
    bottom: 0px;
}

2 个答案:

答案 0 :(得分:0)

只需将overflow: auto;添加到div

即可

&#13;
&#13;
.editable {
  height: 200px;
  width: 500px;
  border: 1px solid #000;
  overflow: auto;
  margin: 20px auto;
}
&#13;
<div class='editable' contenteditable="true">
  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
  survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
  software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

#header
{
    height: 10%;
    top: 0px;
    overflow-y: scroll;
}
相关问题