简体   繁体   中英

CSS div border around child divs

  1. I have one container div, which contains 3 divs inside it.
  2. When i write border:1px solid red for container div, border is shown only on top of these 3 child divs, but not around them.
  3. Below is css code.

     #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 code:

![<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> well solve your problem. added it under the div's

添加overflow:隐藏到#cont元素

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM