ケース1:
- 20pxの可変長で3つの正方形を描きます。色は次のとおりです。
green
black
white
- 一番外側のボックスは影を与えます
颜色purple,XY轴各偏移10px,模糊度10px
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
.box {
width: 100px;
height: 100px;
border-radius: 15px;
background-color: pink;
box-shadow: purple 10px 10px 10px;
}
.square1 {
width: 20px;
height: 20px;
background-color: green;
}
.square2 {
width: 20px;
height: 20px;
background-color: black;
}
.square3 {
width: 20px;
height: 20px;
background-color: white;
}
</style>
<body>
<div class="box">
<div class="square1"></div>
<div class="square2"></div>
<div class="square3"></div>
</div>
</body>
</html>
知識のポイント:
- ボックスシャドウ
box-shadow: X轴偏移度 Y轴偏移度 模糊度 模糊范围
- それ
div
はください
ケース2:
- ワイルドカードを使用して、ページのプリセットスタイルを削除します
- 同じ列に3つの正方形を配置します
- 水平方向と垂直方向の中央に配置
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
/* 通配符 */
* {
margin: 0;
}
.box {
width: 100px;
height: 100px;
border-radius: 15px;
background-color: pink;
box-shadow: purple 10px 10px 10px;
}
.squareBox {
/* 专有名词叫弹性布局,是最常用的布局之一 */
display: flex;
flex-direction: row;
/* 下面两行代码实现水平垂直居中 */
justify-content: center;
align-items: center;
}
.square1 {
width: 20px;
height: 20px;
background-color: green;
}
.square2 {
width: 20px;
height: 20px;
background-color: black;
}
.square3 {
width: 20px;
height: 20px;
background-color: white;
}
</style>
<body>
<div class="box">
<div class="squareBox">
<div class="square1"></div>
<div class="square2"></div>
<div class="square3"></div>
</div>
</div>
</body>
</html>
知識のポイント:
- ワイルドカード
- 柔軟なレイアウト
display: flex
- 水平および垂直センタリングのコード式
.父盒子{
display: flex;
justify-content: center;
align-items: center;
}
考える:
- ボックス内で3つの正方形を水平に中央に配置するにはどうすればよいですか?
- 同じ列に3つのボックスを適切に配置するにはどうすればよいですか?
ヒント:
- MDN、新人チュートリアルSosoに移動します
- 2番目の
justify-content
問題は、のプロパティ値に関連しています。
最終的な効果: