自动高度 div 不起作用

发布于 2024-12-11 11:42:22 字数 2231 浏览 0 评论 0原文

我试图根据其内容使 div 自动调整大小的高度:

 <div id = "bar2">
      <div id = "breadcrumbs"><p>Home &nbsp;>&nbsp; About</p></div>   
      <div id = "anterialtitle"><h1>About</h1></div>
      <div id = "rightblockant"><img src = "img/about.jpg" alt = "About Image | Alternative Text" width = "300" height = "200"/><p class = "firstpara">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p><br/></div>
      <div id = "leftblockant"><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan</p></div>
      </div>
      </div>
    <div id="footer">
                <p><a href ="">About</a>&nbsp;|&nbsp;<a href = "">Contact Us</a>&nbsp;|&nbsp;<a href = "">Shipping Information</a>&nbsp;|&nbsp;<a href = "">Returns Policy</a>&nbsp;|&nbsp;<a href = "">Terms & Conditions</a>&nbsp;|&nbsp;<a href = "">Privacy Policy</a></p>
            <p>&copy; 2011 <a href="" target="_blank">Everry London</a>. All rights reserved.</p>
        </div>



#bar2{  
    width:960px;
    height: auto;
    position:relative;
    margin:0 auto;
    border-left:1px solid #cccccc;
    border-right:1px solid #cccccc;
    border-bottom:1px solid #cccccc;
    border-top:5px solid #313131;
    margin-top:15px;
    margin-left:4px;    
}

然而,这就是结果:

www.everry.com/new/home/about.html

它只封装了 h1 而不是 img 或 p标签..这是为什么?

I'm trying to make the height of a div auto size depending on its contents:

 <div id = "bar2">
      <div id = "breadcrumbs"><p>Home  >  About</p></div>   
      <div id = "anterialtitle"><h1>About</h1></div>
      <div id = "rightblockant"><img src = "img/about.jpg" alt = "About Image | Alternative Text" width = "300" height = "200"/><p class = "firstpara">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p><br/></div>
      <div id = "leftblockant"><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan</p></div>
      </div>
      </div>
    <div id="footer">
                <p><a href ="">About</a> | <a href = "">Contact Us</a> | <a href = "">Shipping Information</a> | <a href = "">Returns Policy</a> | <a href = "">Terms & Conditions</a> | <a href = "">Privacy Policy</a></p>
            <p>© 2011 <a href="" target="_blank">Everry London</a>. All rights reserved.</p>
        </div>



#bar2{  
    width:960px;
    height: auto;
    position:relative;
    margin:0 auto;
    border-left:1px solid #cccccc;
    border-right:1px solid #cccccc;
    border-bottom:1px solid #cccccc;
    border-top:5px solid #313131;
    margin-top:15px;
    margin-left:4px;    
}

However, this is the result:

www.everry.com/new/home/about.html

It only encapsulates the h1 and not the img or the p tags..why is this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

花期渐远 2024-12-18 11:42:22

你把一个 div 关闭太多了

 

Lorem ipsum dolor sat amet,consectetuer adipiscing elit,sed diam nonummy nibh euismod Tincidunt ut laoreet dolore magna aliquamerat volutpat。 Ut wisi enim ad minim veniam, quis nostrud exercitation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan

编辑:抱歉,我现在看到了您的网页,这是用于标题 div 的,很抱歉

you close one div to much

  <div id = "leftblockant"><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan</p></div>
  </div>
  </div>

edit: sorry i saw now your webpage this is for the header div i'm sorry

A君 2024-12-18 11:42:22

漂浮。当您将内容浮动在 div 内并且不“清除”它时,它就会这样做。

您可以通过使用 clear:both 在浮动元素末尾添加一个 div 元素来解决此问题,也可以将 overflow:hidden 添加到 .bar2 >。

我建议您还可以在Google上搜索clearfix以获得更好的解决方案。

Floats. When you float content inside a div and you don't "clear" it it will do that.

You can fix this with adding a div element at the end of the floated elements with clear:both or you can add overflow: hidden to .bar2.

I suggest you also search for clearfix on Google for a better solution.

醉态萌生 2024-12-18 11:42:22

尝试 float:left; 作为 ID 'bar2'

try float:left; for the ID 'bar2'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文