簡體   English   中英

如何在DIV中正確對齊DIV

[英]How to properly Align DIV's within DIV

像大多數人一樣,我將div划分為div。 內部的div分開的左,右正確,但正確的div似乎左格遵循:

在此處輸入圖片說明

html似乎沒有明顯的錯誤:

 .caption{ width: 100%; position: static; } .caption_left{ position: static; width: 65%; background-color: #CDCDC1; padding: 2px; vertical-align: top; } .caption_right { float: right; width: 35%; background-color: white; vertical-align: top; } 
 <h4>[2. Previous]</h4> <div class="caption"> <div class="caption_left"> Left Material </div> <div class="caption_right"> Right Material </div> </div> <p>Some other stuff</p> <h4>[3. Following]</h4> 

我不知道怎么了。 我以前做過,而且效果很好。

caption_left使用float:left

caption_leftcaption_right使用box-sizing

P clear:both使用clear:both :clear屬性指定不允許在元素的哪一側浮動元素浮動。

 .caption { width: 100%; position: static; } .caption_left { float: left; position: static; width: 65%; background-color: #CDCDC1; padding: 2px; vertical-align: top; box-sizing: border-box; } .caption_right { float: right; width: 35%; background-color: red; vertical-align: top; box-sizing: border-box; } p { clear: both; } 
 <h4>[2. Previous]</h4> <div class="caption"> <div class="caption_left"> Left Material </div> <div class="caption_right"> Right Material </div> </div> <p>Some other stuff</p> <h4>[3. Following]</h4> 

嘗試這個

在這里演示

CSS:

.caption{
    width: 100%;
    position: static;
}

.caption_left{
    position: static;
    width: 65%;
    background-color: #CDCDC1;
    padding: 2px;
    vertical-align: top;
    float: left;
}

.caption_right {
    float: right;
    width: 35%;
    background-color: white;
    vertical-align: top;
}
p {
  clear: both;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM