.wrap
{
width:400px;
height:200px;
border:1px solid #000;
}
.content
{
width:300px;
max-height:200px;
background-color:blue;
margin-left:50px;
}
.content p
{
margin:0;
}
.header
{
margin-left:20px;
font-weight:bold;
height:20px;
}
.header p
{
margin:0;
}
<div class="wrap">
<div class="header">
<p>What is Lorem Ipsum?</p>
</div>
<div class="content">
<p>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.</p>
</div>
</div>
你好, 我只是对 CSS 有疑问,我认为也许 JS 是必要的。我希望该段落
始终位于 div(蓝色)中,并且蓝色 div 永远不会超出 div class="wrap"。如果在标题蓝色 div 中添加更多文本,则会降低高度。
最佳答案
制作max-height:180px;
并为.content
添加overflow:hidden
.wrap
{
width:400px;
height:200px;
border:1px solid #000;
}
.content
{
width:300px;
max-height:180px;
background-color:blue;
margin-left:50px;
overflow: hidden;
}
.content p
{
margin:0;
}
.header
{
margin: 0 0 0 20px;
font-weight:bold;
height:20px;
}
.header p
{
margin:0;
}
<div class="wrap">
<div class="header">
<p>What is Lorem Ipsum?</p>
</div>
<div class="content">
<p>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.</p>
</div>
</div>
关于javascript - 最大高度 div 和 div 中以及 div 中的段落,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41207531/