如何用段落填充div高度?

时间:2018-02-20 17:30:36

标签: html css html5 css3

我希望带有类文本的段落内的文本用类包装高度填充父div。



.wrap {
  width: 100%;
  position: absolute;
  bottom: 0;
  text-align: center;
}

.text {
  margin-right: 5%;
  float: left;
  color: #513b60;
  font-size: 280%;
}

.content {
  margin-right: 10%;
  display: flex;
  justify-content: center;
}

<div class='wrap'>
  <p class='text'>Some Text</p>
  <div class='content'>
    <div class='description'>Image Description</div>
    <img src='images/icon.svg' />
  </div>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

这里我们可以获得div高度并将其指定为文本类的字体大小。

这一切都取决于你在内容元素中的含义。要小心,因为如果字体达到高度并且文本分成两行。它会使你的div加倍高度

&#13;
&#13;
$('.text').css('font-size',($('.wrap').height()))
&#13;
.wrap {
  width: 100%;
  position: absolute;
  bottom: 0;
  text-align: center;
  background: red;
}

.text {
margin-top: 0;
margin-bottom: 0;

  margin-right:5%;
  float: left;
  color: #513b60;
  
}

.content {
  margin-right: 10%;
  display: flex;
  justify-content: center;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='wrap'>
  <p class='text'>Some Text</p>
  <div class='content'>
    <div class='description'>Image Description</div>
    <img src='http://via.placeholder.com/50x50' />
  </div>
</div>
&#13;
&#13;
&#13;

希望这就是你要找的东西。如果需要,很乐意解释或帮助提供更好的解决方案。

相关问题