為什么父母或兄弟姐妹有一定的大小,即使它沒有設定?我有下一個片段 在頂部,我有 2 個 div 兄弟。我設定了藍色的大小,為什么紅色的有那個大小?
在底部,我在同一個容器中有 2 個幾何形狀,為什么容器有那個大小?
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.box1 {
background: red;
}
.box2 {
background: blue;
width: 200px;
height: 200px;
}
.container {
background: brown;
}
.child1 {
width: 160px;
height: 160px;
background: yellow;
transform: translate(100px, 100px);
}
.child2 {
width: 300px;
height: 300px;
background: green;
border-radius: 200px;
transform: translateX(100px);
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<link href="teststyle.css" rel="stylesheet">
<title></title>
</head>
<body>
<div class="box1">
<div class="box2"> </div>
</div>
<div class="container">
<div class="child1"></div>
<div class="child2"></div>
</div>
</body>
</html>
uj5u.com熱心網友回復:
Div 有一個默認樣式“顯示:塊”,它將從新行開始并占據整個寬度(您可以在此處閱讀有關顯示的資訊)
因此,box1 的寬度將是其父項寬度的 100%,其高度是 box2 的高度。集裝箱情況類似。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/359306.html
