html - 在页面底部居中 DIV

标签 html css

我试图在页面底部居中放置一个 div,但没有成功。我在网上搜索过,但在尝试应用他们的解决方案时一直没有找到任何结果。

有没有人可能有解决方案?见下面的代码:

<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script></script>
<style type="text/css">
body {
    background-color: aqua;
    height:100%;
    min-height:100%;
}
.centerDiv {
    display: table;
    width:90%; 
    margin:0 auto;
    height:100%;
    min-height:100%;
    text-align: center;
}
.box {
    display: inline-block;
    width: 100px;
    height:100px;
    border: 3px solid #fff;
} 
</style>
</head>
<body>
<div class="centerDiv">
    <div class="box box1" style="background-color:#585858;"> </div>
    <div class="box box2" style="background-color:#118C4E;"> </div>
    <div class="box box3" style="background-color:#C1E1A6;"> </div>
    <div class="box box4" style="background-color:#FF9009;"> </div>
</div>
</body> 
</html>

最佳答案

我想你的意思是,你的 div 将位于页面底部。这将帮助您:

.centerDiv {
    display: block;
    width: 100%; 
    margin: 0 auto;
    height: auto;
    text-align: center;
    position: fixed;
    bottom: 0;
}

将位置设置为固定,div 将随时停留在某个位置(包括向下滚动时)。

关于html - 在页面底部居中 DIV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25353649/

相关文章:

html - 使用 Perl 和 WWW::Mechanize 获取带有填写表单的 HTML 并将其保存到文件

jquery - CSS3 - 动画背景图像过滤器

html - 如何在断点之前忽略外部/父元素

javascript - KineticJs Canvas 中用户的图像 uploader

html - 当 Charles 运行时错误消失,关闭时它返回

javascript - 按下div时如何改变图像?

css - 渐变 - 跨浏览器一致性

javascript - fadeIn() 在调整浏览器大小后重新开始

javascript - 加载页面时如何实现回滚到特定div

javascript - Webpack 4 错误地渲染选择元素