Quantcast
Channel: CSSタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8764

marginの相殺について

$
0
0
★FlexBoxではmarginの相殺が起きない★ HTML <!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CSSの練習</title> <link rel="stylesheet" href="css/styles.css"> </head> <body> <header>Header</header> <div class="container"> <main>Main</main> <nav>Nav</nav> <aside>Aside</aside> </div> </body> </html> CSS html { height: 100%; } body { margin: 0; display: flex; flex-direction: column; height: 100% } header { background: pink; margin-bottom: 100px; } .container { display: flex; flex: 1; margin-top: 50px; } main { background: skyblue; flex: 1; } nav { background: tomato; width: 100px; order: -1; } aside { background: orange; width: 100px; } footer { background: silver; } 上のように header { background: pink; margin-bottom: 100px; } .container { display: flex; flex: 1; margin-top: 50px; } だとmarginが打ち消されてmargin-bottom:100pxだけが適用されそうだが、 FlexBoxなので両方適用されて150pxとなる。

Viewing all articles
Browse latest Browse all 8764

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>