在父div中将两个子div放在一起

时间:2012-10-21 18:25:09

标签: html css

这就是我到目前为止所得到的: http://jsfiddle.net/cHKF4/3/

但是我想把小盒子(盒子1和盒子2放在里面)

#late {
    position: relative;
    border-style: solid;
    border-width: 3px;
    border-color: #00fff3;
    height: 200px;
       width: 960px;
    margin: 0 auto;
    margin-top: 30px;
}

#box1 {
    position: relative;
    border-style: solid;
    border-width: 1px;
    border-color: #55fff3;
    height: 100%;
    width: 200px;
    margin: 0 auto;
}

#box2 {
    position: relative;
    border-style: solid;
    border-width: 3px;
    border-color: #55fff3;
    height: 100%;
    width: 200px;
}

谢谢。

4 个答案:

答案 0 :(得分:2)

Is this what you're trying to achievebox1box2并排在late内,late位于页面的中心位置):

<div id="late">
    <div id="inner">
       <div id="box1"></div>
       <div id="box2"></div>
    </div>
</div>​

#late {
    border: solid 3px #00fff3;
    height: 200px;
    width: 960px;
    margin: 30px auto 0 auto;
}

#inner {
    width: 408px;
    height: 100%;
    margin: 0 auto 0 auto;
}

#box1 {
    border: solid 1px #55fff3;
    height: 100%;
    width: 200px;
    float: left;
}

#box2 {
    border: solid 3px #55fff3;
    height: 100%;
    width: 200px;
    float: left;
}
​

答案 1 :(得分:1)

我不太明白你想要实现的目标。你想把#box1和#box2集中在#late吗?

如果您只是想将它们并排放在#late中,我就会这样做:http://codepen.io/AntonNiklasson/pen/rIdcj

答案 2 :(得分:1)

float:left添加到#box1#box2

#box1 {
    float:left;
    position: relative;
    border-style: solid;
    border-width: 3px;
    border-color: #55fff3;
    height: 100%;
    width: 200px;
}

#box2 {
    float:left;
    position: relative;
    border-style: solid;
    border-width: 3px;
    border-color: #55fff3;
    height: 100%;
    width: 200px;
}

答案 3 :(得分:1)

尝试

#box1 {
position: absolute;
top: 10px;
left: 10px;
}

将父容器的位置设置为相对。