gpt4 book ai didi

html - Flexbox 的挣扎

转载 作者:太空宇宙 更新时间:2023-11-04 07:37:07 25 4
gpt4 key购买 nike

我正在努力使用 flexbox 创建固定的页眉和页脚。页眉和页脚实际上仅由每一侧的一个元素组成。我想让元素固定,中间的内容可滚动。我也不明白如何将页脚放置在视口(viewport)底部。

enter image description here

其实没什么疯狂的,但我不明白我做错了什么?

body {
font-family: DejaVu Sans Mono;
min-height: 100vh;
}

nav a {
margin: 0;
padding: 0;
display: block;
text-decoration: none;
text-align: center;
}

nav ul {
list-style-type: none;
}

.intro-container {
display: flex;
}

.intro-text {
font-size: 42px;
line-height: 52px;
}

.placeholder {
width: 500px;
height: 800px;
position: absolute;
left: 65vw;
top: 85vh;
background-color: lightgrey;
}



@media screen and (min-width: 300px) {

.top ul {
margin: 0;
padding: 0;
display: flex;
justify-content: space-between;
}

.bottom ul {
margin: 0;
padding: 0;
top: 100vh;
display: flex;
justify-content: space-between;
}

nav {
}


}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="style.css">
</head>
<body>


<nav class="top">
<ul>
<li> <a href="index.html"> text1 </a> </li>
<li> <a href=""> text2 </a> </li>
</ul>
</nav>

<div class="intro-container">
<h1 class="intro-text">
Lorem Ipsum
</h1>
</div>

<nav class="bottom">
<ul>
<li> <a href=""> text3 </a> </li>
<li> <a href=""> text4 </a> </li>
</ul>
</nav>



</body>
</html>

最佳答案

使用 flex 属性将 anchor 固定到所有四个 Angular 。

然后使用 overflow: auto 使内容可滚动。

body {
display: flex;
flex-direction: column;
justify-content: space-between; /* pin header and footer to top and bottom edges */
height: 100vh;
margin: 0;
}

nav {
display: flex;
justify-content: space-between; /* pin anchors to left and right edges */
}

nav a {
font-size: 1.5em;
background-color: lightgreen;
text-decoration: none;
}

.intro-container {
flex: 1;
background-color: yellow;
overflow: auto;
}
<nav class="top">
<a href="index.html"> text1 </a>
<a href=""> text2 </a>
</nav>

<div class="intro-container">
<h1 class="intro-text">
Lorem Ipsum
</h1>
<p>I'm struggling to create a fixed header and footer using flexbox. Header and footer actually consists just of an element on each side. I'd like to make the elements fixed and the content in the middle scrollable. I also don't get it how to position
my footer at the bottom of the viewport.</p>
<p>I'm struggling to create a fixed header and footer using flexbox. Header and footer actually consists just of an element on each side. I'd like to make the elements fixed and the content in the middle scrollable. I also don't get it how to position
my footer at the bottom of the viewport.</p>
<p>I'm struggling to create a fixed header and footer using flexbox. Header and footer actually consists just of an element on each side. I'd like to make the elements fixed and the content in the middle scrollable. I also don't get it how to position
my footer at the bottom of the viewport.</p>
<p>I'm struggling to create a fixed header and footer using flexbox. Header and footer actually consists just of an element on each side. I'd like to make the elements fixed and the content in the middle scrollable. I also don't get it how to position
my footer at the bottom of the viewport.</p>
<p>I'm struggling to create a fixed header and footer using flexbox. Header and footer actually consists just of an element on each side. I'd like to make the elements fixed and the content in the middle scrollable. I also don't get it how to position
my footer at the bottom of the viewport.</p>
<p>I'm struggling to create a fixed header and footer using flexbox. Header and footer actually consists just of an element on each side. I'd like to make the elements fixed and the content in the middle scrollable. I also don't get it how to position
my footer at the bottom of the viewport.</p>
<p>I'm struggling to create a fixed header and footer using flexbox. Header and footer actually consists just of an element on each side. I'd like to make the elements fixed and the content in the middle scrollable. I also don't get it how to position
my footer at the bottom of the viewport.</p>
<p>I'm struggling to create a fixed header and footer using flexbox. Header and footer actually consists just of an element on each side. I'd like to make the elements fixed and the content in the middle scrollable. I also don't get it how to position
my footer at the bottom of the viewport.</p>
<p>I'm struggling to create a fixed header and footer using flexbox. Header and footer actually consists just of an element on each side. I'd like to make the elements fixed and the content in the middle scrollable. I also don't get it how to position
my footer at the bottom of the viewport.</p>
</div>

<nav class="bottom">
<a href=""> text3 </a>
<a href=""> text4 </a>
</nav>

jsFiddle demo

关于html - Flexbox 的挣扎,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48855971/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com