html - 设置div的高度

标签 html css height

我想根据子元素设置部分的高度,但不幸的是我不知道我的代码有什么问题。当我尝试减小屏幕大小时,段落中的内容和 img 溢出。

HTML

<div id="section2" class="about">
      <div class="container-section">
         <div class="about-content col-lg-6">
            <p></p>
         </div>
         <div class="about-pic col-lg-2">
            <img />
         </div>
      </div>
 </div>

CSS

.about{
height: auto;
margin: 0;
}
.about .container-section{
padding: 0;
height: auto;
position: relative;
}
.about .container-section .about-content p{
padding-bottom: 15px;
font-family: 'Lato', sans-serif;
text-align: justify;
}
.about .container-section .about-pic img{
height: auto;
width: 100%;
padding-bottom: 25%;
} 

有什么建议吗?

最佳答案

好的,看起来您正在使用 Bootstrap,对吧? Bootstrap 正在添加一些 float 元素,这会从页面流中移除元素,因此容器的行为就好像这些元素不在其中一样。尝试在不同的地方添加一个清除的 div,看看它是否能解决您的问题,如下所示:

<div id="section2" class="about">
  <div class="container-section">
     <div class="about-content col-lg-6">
        <p></p>
     </div>
     <div class="about-pic col-lg-2">
        <img />
     </div>
  </div>
  <div style="clear:both;"></div>
</div>

关于html - 设置div的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39314539/

相关文章:

c - N个节点的完全二叉树的高度是多少?

javascript - JS检测div在屏幕下方的高度

html - 旋转 html 特殊字符或文本

jquery - CSS 仅在达到 max-height 时才增加宽度

css - float 布局不好吗?应该用什么代替它?

javascript - 网站滚动问题

ios - 获取 UIWebView 内容的高度

html - 在打印页面上使用 Google Chrome 重复表格标题

html - 为什么我的网站在智能手机上显示两个标题?

javascript - 是否有客户端方法来检测 X-Frame-Options?