html - 是否可以将内容插入 DIV 但 DIV 保持相同大小?

标签 html css

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

顶部 DIV 高度:10%,中间 DIV 高度:88%,底部 DIV 高度: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;
}

最佳答案

只需将 overflow: auto; 添加到 div

.editable {
  height: 200px;
  width: 500px;
  border: 1px solid #000;
  overflow: auto;
  margin: 20px auto;
}
<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>

关于html - 是否可以将内容插入 DIV 但 DIV 保持相同大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43206618/

相关文章:

css - 如何更改纸质按钮的纸质 Material 框阴影的颜色? ( polymer 1.0+)

html - 在仅限网站的 1080 像素及更低屏幕上,横幅图像和菜单栏之间的空白区域。怎么修?

javascript - 在 magento 管理后端取消 merge css 和 js 文件

jquery - 如何添加图像

javascript - 检查类是否包含img src,如果不包含,则隐藏它。 jQuery

html - 将联系页面链接到 HTML5 中的主页

javascript - 磁盘和垂直矩形之间的碰撞检测

html - 带滚动的 div 中的空白区域

html - Div 超过 2 个其他 div?

javascript - 如果 li 为空,则在 jQuery 中隐藏 excluding span 属性