Skip to content

Instantly share code, notes, and snippets.

@sou5534
Last active June 13, 2018 00:05
Show Gist options
  • Save sou5534/2f9fd47daf05a9d674f7456aaa2f9cb2 to your computer and use it in GitHub Desktop.
Save sou5534/2f9fd47daf05a9d674f7456aaa2f9cb2 to your computer and use it in GitHub Desktop.
marginを使う方法 子要素に「margin: auto;」を定義します。必要に応じて「text-align:center;」 flexboxを使う方法 親要素に「display:flex;」「justify-content:center;」「align-items: center;」
.child {
display:inline-block;
font-family: Arial;
font-weight: bold;
color: white;
font-size: 1.5em;
text-align: center;
}
.parent.one {
display:flex;
background: blue;
}
.parent.one .child {
margin:auto;
}
.parent.two {
margin-left: 10px;
display:flex;
justify-content:center;
background: red;
align-items: center;
}
<div class="parent one">
<div class="child">WITH MARGIN</div>
</div>
<div class="parent two">
<div class="child">WITH FLEX</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment