Last active
June 13, 2018 00:05
-
-
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;」
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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