我正试着遵循一些建议,这些建议涉及不使用边距进行间距设置,而是使用具有列方向和间距属性的 flex 容器。这样做更好,只是我无法找出如何在需要为单个 flex 项设置背景颜色时退出容器。
https://codepen.io/Xe11o/pen/VwVOpPP
.container {
display: flex;
flex-direction: column;
max-width: 1130px;
margin: 20px auto 0 auto;
gap: 50px;
}
header {
display: flex;
justify-content: space-between;
}
nav {
display: flex;
}
section {
font-size: 50px;
}
footer {
font-size: 25px;
background: lightgray;
}
<html>
<body>
<div class='container'>
<header>
<span>title text</span>
<nav>
<button>button link 1</button>
<button>button link 2</button
</nav>
</header>
<section>main content</section>
<footer>
Footer content.
<br />
How do i get this background color to stretch beyond the flex container to the edge of the screen?
<br />
I can remove the max-width+margin from the container and apply them instead to the children (header, section), then maybe do an align-items on the container, but then I can't get the header to look like it does right now.
</footer>
</div>
</body>
</html>
absolute
或relative
的容器中,创建一个新的相对定位视图堆栈。这就是我所说的"breaking out"。 - lupz