[英]HTML container div occupying extra space bellow its child item?
從container-team
樣式中刪除比例轉換。 這就是導致您的頁面出現問題的原因。
快速而骯臟的解決方案是向父容器添加負的邊距:
.container-team {
max-width: 1170px;
width: 100%;
margin: 0px auto;
margin-bottom: -25%;
padding: 0 0px;
box-sizing: border-box;
-webkit-transform-origin: top center;
transform-origin: top center;
-webkit-transform: scale(0.8);
transform: scale(0.8);
}
https://codepen.io/anon/pen/eXJNBw?editors=1100
但是,看到此額外空白的原因是因為您將所有內容縮放了0.8。 每當執行css transform: scale
,它都會在進行縮放之前創建布局,這意味着元素的位置相對於1.0縮放時的位置。 之所以將其綁定到頂部,是因為使用transform-origin: top center
將css設置為這種方式,它將轉換后的元素放在頂部和中央。 如果刪除此選項,它將簡單地將其全部縮小0.8,從而在頂部和底部添加空白。
負邊距修復很好,但是如果您想要一個更強大的解決方案,則應該考慮將每個用戶元素縮小並使用margin-left和margin-right而不是整個縮放。
您必須以與元素.container-team對應的樣式添加高度值。 以下樣式可以解決問題:
height: -webkit-fill-available;
添加其他任何高度值也可以
height: 100px;
我將您的最后一個div移到了上一個div。
現在,您應該能夠添加所需的間距,而無需所有額外的間距: https : //codepen.io/anon/pen/BbjyYW?editors=1100
<div style="background-color: #999;"> next item </div>
如果您不希望所有間距都一樣,但又不想將最后一個div放在container-team div內,則將container-team div和“ next item” div嵌套在另一個div內,如下所示:
<div> <div class="container-team"> Container team content </div> <div style="background-color: #999;"> next item </div> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.