marginの相殺について
★FlexBoxではmarginの相殺が起きない★
(ドットインストール 「詳解CSS フレックスボックス編 #11 縦方向に要素を配置してみよう」)
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となる。
Author And Source
この問題について(marginの相殺について), 我々は、より多くの情報をここで見つけました https://qiita.com/shun0000/items/15ef0adb2cf03a70597a著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .