<!DOCTYPE html>
<html>
<head>
<style>
#container {
width: 70%;
aspect-ratio: 2/1;
border: 1px solid black;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
#container > div {
border: 1px solid black;
}
.blue {
background-color: lightblue;
width: 60%;
justify-self: right;
}
.red {
background-color: coral;
width: 80%;
}
.green {
background-color: lightgreen;
width: 70%;
}
</style>
</head>
<body>
<h1>justify-self: right</h1>
<p>默认情况下,所有网格项目都向左对齐,除了已设置 justify-self 属性值 'right' 的蓝色网格项目。</p>
<div id="container">
<div class="red">红色</div>
<div class="blue">蓝色<br>justify-self: right</div>
<div class="green">绿色</div>
<div class="red">红色</div>
<div class="green">绿色</div>
<div class="red">红色</div>
<div class="green">绿色</div>
<div class="red">红色</div>
<div class="green">绿色</div>
</div>
</body>
</html>