簡體   English   中英

CSS div邊界圍繞子div

[英]CSS div border around child divs

  1. 我有一個容器div,其中包含3個div。
  2. 當我寫邊框時:1px為容器div的實心紅色,邊框僅顯示在這3個子div的頂部,但不在它們周圍。
  3. 下面是css代碼。

     #cont { width:800px; margin-right:auto; margin-left:auto; border:1px dashed red; padding:2px; } #third, #second, #first { width:260px; float:left; margin:2px; } 

Html代碼:

![<div id="cont">
<div id="third"><p>A demo text </p></br>
<p>A demo text </p></br>
<p>A demo text </p></br>
<p>A demo text </p></br>
</div>

<div id="second"><p>A demo text </p></br>
<p>A demo text </p></br>
<p>A demo text </p></br>
<p>A demo text </p></br>
</div>

<div id="third"><p>A demo text </p></br>
<p>A demo text </p></br>
<p>A demo text </p></br>
<p>A demo text </p></br>
</div>
</div>][1]

添加溢出:隱藏;

#cont {width:800px;margin-right:auto;margin-left:auto; border:1px dashed red;padding:2px; overflow:hidden;}

<div style="clear:both;float:none;"></div>很好地解決了你的問題。 在div下添加它

添加overflow:隱藏到#cont元素

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM