我有一個主要的DIV,它是帶有頁邊距的屏幕中心:0 auto;現在我需要在主DIV旁邊添加另一個div(右側)..並且如果我增加或減少屏幕尺寸,則該帖子不應該移動...任何幫助?另一個div位於主div旁邊
<div style="width:320px; height:500px; background-color:#C60; margin:0 auto;">Main Div</div> <div>Another DIV</div>
感謝
我有一個主要的DIV,它是帶有頁邊距的屏幕中心:0 auto;現在我需要在主DIV旁邊添加另一個div(右側)..並且如果我增加或減少屏幕尺寸,則該帖子不應該移動...任何幫助?另一個div位於主div旁邊
<div style="width:320px; height:500px; background-color:#C60; margin:0 auto;">Main Div</div> <div>Another DIV</div>
感謝
添加到樣式:
display:inline-block;
或者
float:left;
如果你喜歡最後一個,那麼你可能都喜歡的div後添加一個空div清除間距
<div style="clear:both"></div>
float: left
將正常工作......
HTML代碼:
<div class="outer">
Main Div
</div>
<div class="inner">Another DIV</div>
CSS代碼:
.outer {
width:220px;
height:100px;
background-color:#C60;
float: left;
}
.inner {
width:120px;
height:100px;
background-color:red;
float: left;
}
這是的jsfiddle link
更新:
jsfiddel link
但主要的div應該在頁面的中心,另一個在它旁邊..任何可能性? – 2013-02-21 08:59:32
使用'margin'或'position' – TNK 2013-02-21 09:03:15
當我申請保證金時它不起作用:0 auto和float:left – 2013-02-21 09:22:24
你想這兩個容器爲中心一起,或者一個主要要在自己的心像現在,另一個是關閉到它的一面呢? – 2013-02-21 08:47:10
完全一樣,主要應該居中,另一個應該靠近主格。 – 2013-02-21 08:54:31