javascript - 最大高度 div 和 div 中以及 div 中的段落

标签 javascript html css

.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/

相关文章:

javascript - 正则表达式捕获组适用于 Javascript 和 regex101,但不适用于 sed

javascript - 英特尔XDK |安卓应用程序 |无法将用户输入发布到 Facebook 群组

css - 如何正确定位div

javascript - 在 Iframe 中反转/更改 nen html 页面的颜色

javascript - 将元素置于模态背景之上

javascript - 2020 年后 Javascript 月份错误

javascript - 使用 Javascript 在构造函数中使用数组

html - 我网站上的 firefox 用户出现奇怪的黑条

javascript - 秒表不工作

javascript - 通过动态路径时出现问题