将两个子div放在parrent div中

时间:2021-06-14 19:18:15

that's what I got so far: http://jsfiddle.net/cHKF4/3/

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

But I want to put small boxes (box1 and box2 inside late)

但我想放小盒子(盒子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;
}

Thank you.

4 个解决方案

#1


2  

Is this what you're trying to achieve (box1 and box2 side by side and centred inside late with late centred on the page) :

这是你想要实现的目标(box1和box2并排并且在晚期居中,并且在页面中间居中):

<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;
}
​

#2


1  

I don't quite understand what you are trying to achieve. Are you trying to center #box1 and #box2 inside #late?

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

If you are just trying to put them side by side inside #late this is how I would do it: http://codepen.io/AntonNiklasson/pen/rIdcj

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

#3


1  

Add float:left to both #box1 and #box2

将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;
}

#4


1  

Try

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

Keep the parent container's position set to relative.

保持父容器的位置设置为相对。

#1


2  

Is this what you're trying to achieve (box1 and box2 side by side and centred inside late with late centred on the page) :

这是你想要实现的目标(box1和box2并排并且在晚期居中,并且在页面中间居中):

<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;
}
​

#2


1  

I don't quite understand what you are trying to achieve. Are you trying to center #box1 and #box2 inside #late?

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

If you are just trying to put them side by side inside #late this is how I would do it: http://codepen.io/AntonNiklasson/pen/rIdcj

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

#3


1  

Add float:left to both #box1 and #box2

将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;
}

#4


1  

Try

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

Keep the parent container's position set to relative.

保持父容器的位置设置为相对。