我創建了一個工作正常的小提琴,但每當我試圖添加一個額外的左填充到lef-col
,其他兩個div向下移動。向div添加額外的填充,導致其他div向下移動 - CSS?
我期待的是,填充適用於div的內部內容和外部邊界,但在這種情況下,它看起來像是增加了div
計算。讓我知道我錯誤地理解了傳球。
PS-I通過將box-sizing: border-box
應用於left-col
進行了修正。我找e.xplanation這個原因不是解決方案(雖然替代解決方案也歡迎!)
碼 -
HTML -
<div class="container">
<div class="left-col">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dignissimos illum perferendis corporis, nemo dolorem, mollitia at sequi quis corrupti. Fugit eaque dolores inventore, aliquam quisquam, saepe officiis eos quia at!</p>
</div>
<div class="mid-col">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dignissimos illum perferendis corporis, nemo dolorem, mollitia at sequi quis corrupti. Fugit eaque dolores inventore, aliquam quisquam, saepe officiis eos quia at!</p>
</div>
<div class="right-col">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dignissimos illum perferendis corporis, nemo dolorem, mollitia at sequi quis corrupti. Fugit eaque dolores inventore, aliquam quisquam, saepe officiis eos quia at!</p>
</div>
</div>
CSS -
*, html {
margin: 0;
padding: 0;
}
body {}
.container {
padding: 20px;
overflow: hidden;
}
.left-col, .mid-col, .right-col {
width: 33.3%;
float: left;
}
.left-col {
background: lightpink;
}
.mid-col {
background: lightgreen;
}
.right-col {
background: lightblue;
}
小提琴 - https://jsfiddle.net/km2brd8m/