gpt4 book ai didi

html - 如何让页脚始终在底部

转载 作者:行者123 更新时间:2023-12-02 02:42:24 26 4
gpt4 key购买 nike

我正在制作一个网站,我试图使页脚始终位于底部。我希望页脚始终位于浏览器窗口的底部,但如果内容足够长,它会将页脚推到视线之外并进一步位于底部。现在,页脚始终位于紧邻其上方内容之后的位置。

enter image description here

我尝试设置display: flex, flex-direction, align-items: flex-end, margin-bottom: 0px ,但没有成功。我还试图避免设置固定高度。

相关代码

页脚.js

<footer className='footer'>
<div className='icons'>
<span><a href='/'><img src={LinkedIn} alt='LinkedIn'/></a></span>
<span><a href='/'><img src={Mail} alt='Email' /></a></span>
<span><a href='/'><img src={Resume} alt='Resume' /></a></span>
</div>
<div>
<span className='footer-link'><a href='/'>Home</a></span>
<span className='footer-link'><a href='/about'>About</a></span>
<span className='footer-link'><a href='/blog'>Blog</a></span>
<span className='footer-link'><a href='/contact'>Contact</a></span>
</div>
<div className='footer-copyright'>2020 Daniel Zhang. This site was made by Daniel Zhang from scratch with React.</div>
</footer>
.footer {
align-items: center;
border-top: 1px solid grey;
border-width: 100%;
box-sizing: border-box;
display: flex;
flex-direction: column;
flex-shrink: 0;
font-size: 12px;
margin: 0px auto;
padding: 10px 0px;
text-align: center;
}

.icons img {
display: inline-block;
padding: 10px;
width: 25px;
}

.footer-link {
padding: 0px 5px;
}

.footer-link a {
color: grey;
text-decoration: none;
}

.footer-link a:hover {
color: black;
text-decoration: none;
}

.footer-copyright {
padding: 5px 0px;
}

App.js

<NavBar />
<Router>
<Switch>
<Route exact path='/' render={() => <Home />} />
<Route exact path='/about' render={() => <About />} />
<Route exact path='/blog' render={() => <Blog />} />
<Route exact path='/contact' render={() => <Contact />} />
{/* Adds page not found. */}
<Route render={() => <Home />} />
</Switch>
</Router>
<Footer />

应用程序.css

* {
font-family: 'Lato', sans-serif;
}

html, body {
height: 100%;
margin: 0px;
}

body {
display: flex;
flex-direction: column;
}

.container {
flex: 1 0 auto;
margin: 0px auto;
width: 65%;
}

最佳答案

尝试flex-direction:column;

document.getElementById('add').addEventListener('click', e => {
document.getElementById('content').innerHTML += '<br />content<br />content<br />content';
});
html,
body {
margin: 0;
height: 100%;
}

body {
display: flex;
flex-direction: column;
}

.content {
flex: 1 0 auto;
}

.footer {
background: #999;
flex-shrink: 0;
}
<body>
<div class="content">
<button id="add">Add Content</button>
<p id="content">content</p>
</div>
<footer class="footer">footer</footer>
</body>

关于html - 如何让页脚始终在底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63351135/

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