简体   繁体   English

CSS div边界围绕子div

[英]CSS div border around child divs

  1. I have one container div, which contains 3 divs inside it. 我有一个容器div,其中包含3个div。
  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. 当我写边框时:1px为容器div的实心红色,边框仅显示在这3个子div的顶部,但不在它们周围。
  3. Below is css code. 下面是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 code: 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> well solve your problem. <div style="clear:both;float:none;"></div>很好地解决了你的问题。 added it under the div's 在div下添加它

添加overflow:隐藏到#cont元素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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