如何使Box元素自动扩展?

时间:2013-11-13 20:56:31

标签: html css css-float collapse

下面的链接显示了我正在处理的网站的简化版本以及我提出的问题。

我有几个封装的盒子元素。主容器和容器内的几个div将保存内容,当内容扩展时,我需要容器div自动扩展。除非我在CSS中添加特定的高度,否则我似乎无法完成此任务。

JSFiddle Example

HTML:

<body>
<div id="container">
    <div id="block1">
        <div id="one">one</div>
        <div id="two">two<br />two<br /></div>
        <div id="three">three<br />three<br />three<br /></div>
        <div id="four">four<br />four<br />four<br />four<br /></div>
    </div>
</div>
</body>

CSS:

#container {
width: 1050px;
margin: auto;
padding: 5px;
background-color: #ededf0;
background: 
   url("http://wguayan.comuv.com/brushed_metal_clear_apple.jpg") repeat;
}

#one, #two, #three, #four {
border-width: 1px;
border-color: black;
border-style: solid;
background-color: white;
border-radius:6px;
-moz-border-radius:6px;
/* Firefox 3.6 and earlier */
}

#one {
width: 100px;
position: relative;
top: 0px;
left: 0px;
padding: 10px;
box-shadow: 9px 9px 12px #888888;
}

#two {
float: left;
width: 100px;
position: relative;
top: 0px;
left: 0px;
padding: 5px;
text-align: center;
box-shadow: 9px 9px 12px #888888;
}

#three {
float: left;
width: 100px;
position: relative;
top: 0px;
left: 0px;
padding: 10px;
box-shadow: 9px 9px 12px #888888;
}

#four {
float: left;
width: 100px;
position: relative;
top: 0px;
left: 0px;
padding: 10px;
box-shadow: 9px 9px 12px #888888;
}

#block1 {
width: 100%;
border-width: 1px;
border-color: black;
border-style: solid;
}

1 个答案:

答案 0 :(得分:0)

只需将overflow: hidden应用于#block1

即可