Posted at

要素を左右に寄せる方法

More than 1 year has passed since last update.

display:flexを用いて子要素を左右に寄せる方法


html

<div class="parent">

<div class="child1"></div>
<div class="child2"></div>
</div>


css

.parent{

display: flex;
}

/*左に寄せる*/
.child1{
magin-left: 0;
margin-right: auto;
}

/*右に寄せる*/
.child2{
magin-left: auto;
margin-right: 0;
}