html - 对齐底部和响应式设计
问题描述
我想在其底部建立一个带有横幅的页面。如果我的页面足够大,我的代码可以正常工作,但如果我减小屏幕宽度,一切都会重叠。如果屏幕不够宽,我希望显示我的页面,并且只有在横幅显示之后,就好像它是一个在另一个下的两个 div。你能帮我吗 ?
我的页面是这样构建的
<div class="sp-page-home" >
<p>the content of the page</p>
<div style="position: absolute;bottom: 0;left: 0;right: 0">the content of the banner</div>
</div>
我的CSS:
.sp-page-home {
width: 100%;
background: url(../img/home.png) no-repeat center;
-webkit-background-size: cover;
background-size: cover;
position: relative;
min-height: 100%;
overflow: hidden;
}
谢谢你的帮助
解决方案
您需要将 html 和 body 标签的高度设置为 100%。
.sp-page-home {
width: 100%;
background: url(../img/home.png) no-repeat center;
-webkit-background-size: cover;
background-size: cover;
position: relative;
min-height: 100%;
overflow: hidden;
}
html, body{
height: 100%;
}
<div class="sp-page-home" >
<p>the content of the page</p>
<div style="position: absolute;bottom: 0;left: 0;right: 0">the content of the banner</div>
</div>
.sp-page-home {
width: 100%;
background: url(../img/home.png) no-repeat center;
-webkit-background-size: cover;
background-size: cover;
position: relative;
min-height: 100%;
overflow: hidden;
}
html, body{
height: 100%;
}
<div class="sp-page-home" >
<p>the content of the page</p>
<p>the content of the page</p>
<p>the content of the page</p>
<p>the content of the page</p>
<p>the content of the page</p>
<p>the content of the page</p>
<p>the content of the page</p>
<p>the content of the page</p>
<p>the content of the page</p>
<p>the content of the page</p>
<p>the content of the page</p>
<p>the content of the page</p>
<div style="position: absolute;bottom: 0;left: 0;right: 0">the content of the banner</div>
</div>
推荐阅读
- reactjs - React.createElement:类型无效但 TypeScript 编译正确。为什么?
- r - 无法在 R Studio 中安装“ez”包
- python-3.x - KeyError: 'TCL_LIBRARY' 使用 cx_freeze 构建时
- visual-studio - 创建自己的包管理器控制台命令?
- android - 手机解锁时的启动器动画
- java - 通过不同方法处理异常进行代码重构
- r - 不能强制增益函数的结果输入“双”
- python - 模块“xml.dom”没有属性“节点”
- java - 如何使用外部 java 库在命令行中编译和运行 kotlin 程序
- mysql - 如何让这个 MySQL 查询运行得更快?