簡體   English   中英

如何將不同的 div 堆疊在一起(應該是響應式的)

[英]How to stack different divs on each other (should be responsive)

我剛剛開始處理 HTML 和 CSS。我想堆疊不同的 div(見圖)。

黑色的 div 代表容器。 紅色 div 為 header,藍色為圓心,圓心位於紅色 div 的底部邊緣。

解決方案最終也應該是響應式的。 我在這里需要考慮什么?

在此處輸入圖像描述

 .container { height: 300px; width: 600px; background-color: black; text-align: center; }.header { height: 40%; width: 100%; background-color: red; }.circle { background-color: blue; height: 100px; width: 100px; border-radius: 50%; display: inline-flex; }
 <div class="container"> <div class="header"> <div class="circle"></div> </div> </div>

你可以使用positionflexbox

 .container { height: 300px; width: 80%; margin: 0 auto; background-color: black; text-align: center; }.header { height: 40%; width: 100%; background-color: red; position: relative; display: flex; justify-content: center; }.circle { background-color: blue; height: 100px; width: 100px; border-radius: 50%; display: inline-flex; position: absolute; bottom: 0; transform: translateY(50%); }
 <div class="container"> <div class="header"> <div class="circle"></div> </div> </div>

使header相對,並將圓圈底部與translate對齊。

 .container { height: 300px; width: 600px; background-color: black; text-align: center; }.header { height: 40%; width: 100%; background-color: red; position: relative; /* make header container relative */ }.circle { background-color: blue; height: 100px; width: 100px; border-radius: 50%; display: inline-flex; /* bottom position with centered circle */ position: absolute; left: 50%; bottom: 0; transform: translate3d(-50%, 50%, 0); }
 <div class="container"> <div class="header"> <div class="circle"></div> </div> </div> <hr /> <:-- Option with bigger header --> <div class="container"> <div class="header" style="height; 70%;"> <div class="circle"></div> </div> </div>

暫無
暫無

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

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