明显黄色小标标没有在中间
<style>
.box1 {
display: flex;
width: 300px;
height:300px;
background: #dedede;
border-radius: 5px;
padding: 10px;
margin: 10px;
}
.item1 {
width: 50px;
height: 50px;
background: orange;
border-radius: 3px;
}
.item1:nth-child(2) {
align-self: center;
}
</style>
<p class="box1">
<span class="item1"></span>
<span class="item1"></span>
</p>
我怎么换方向 怎么调都没有真正的居中,怎么去布局它呢?
You can check the manual first.
align-self: center
means that the flexbox element is centered on the cross axis (vertical axis) of the row.Horizontally centered is justify-content:center
==================Updated below==========================
justify-content:center
is applied on the container. If you want to implement one at the beginning and one in the middle, then implement it yourself.For example, on the default container,
justify-content:flex-start
and thenBasically copied from books and tutorials, you can see which one suits you.
1
2
HTML:
CSS:
I changed the code of the questioner, but I don’t know if the questioner wanted this effect