[英]How to make footer stay at bottom of the page?
Im trying to build a simple single page react project where data is fetched from a public API and then it renders the data to the site.我正在尝试构建一个简单的单页反应项目,其中从公共 API 获取数据,然后将数据呈现到站点。 When styling my project I stumbled across a problem where my footer component doesnt stay at the bottom of the site.
在为我的项目设计样式时,我偶然发现了一个问题,即我的页脚组件没有位于网站底部。
I googled the solutions with stylings like:我用谷歌搜索了具有以下样式的解决方案:
.footer__container {
margin: auto;
width: 100%;
position: absolute;
right: 0;
left: 0;
bottom: 0;
background-color: #efefef;
text-align: center;
}
This works good if data is not rendered into the site: Correct如果数据未呈现到站点中,这会很好用:正确
But when data is rendered to the website, the footer component stays at the same place.但是当数据呈现给网站时,页脚组件会留在同一个地方。 When scrolling down, it doesnt move along.
向下滚动时,它不会移动。 Example
例子
Without position: absolute;
没有
position: absolute;
and styling和造型
.footer__container {
margin: auto;
height: 60px;
background-color: #efefef;
margin-top: 2.5rem;
text-align: center;
}
it stays at the bottom when data is rendered to the site.当数据呈现到网站时,它会停留在底部。 But the start view is this: Without data rendered .
但开始视图是这样的:没有呈现数据。
App.js:应用程序.js:
function App() {
return (
<div className="App">
<Header/>
<Form/>
<Footer/>
</div>
);
}
Form.jsx表单.jsx
return (
<div className="form__section">
<form onSubmit={handleFetch}>
<input
value={word}
onChange={(e) => setWord(e.target.value)}
id='enter__word'
className='form__input'
></input>
<button>Search</button>
</form>
<div className='word__section'>
{synonyms.map((synonym) => (
<div className="word__container" key={synonym.word}>
<ul>
<li>
{synonym.word}
</li>
</ul>
</div>
))}
</div>
</div>
)
Please remove the position: absolute;
请删除
position: absolute;
and add the min-height: calc(100vh - HEADER_HEIGHT - FOOTER_HEIGHT)
to form__section
.并将
min-height: calc(100vh - HEADER_HEIGHT - FOOTER_HEIGHT)
添加到form__section
。
If you have something like CodeSandbox , I will modify it there.如果你有类似CodeSandbox的东西,我会在那里修改它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.