我有我正在处理的网页。关于它的一切都在响应性方面正常运行,但是,只有页脚不能正常工作。当屏幕变小时,我希望页脚的3个部分显示在彼此之下。非常感谢任何帮助。看看下面的代码:
HTML:
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>Papia</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<!--- This is the path to the image that will display on mobile --->
<video poster="assets/backupimage.jpg" id="bgvid" playsinline autoplay muted loop>
<!--- Inlcude the video files with .webm file first --->
<source src="assets/papia.webm">
<source src="assets/papia.mp4">
<source src="assets/papia.mov">
</video>
<div id="topLeft">
<img src="assets/papia-logo-secondary.svg">
</div>
<div id="topRight">
<a href="http://www.google.com" target="_blank">Find a table</a>
</div>
<div id="logo">
<img src="assets/papia-logo-main.svg">
</div>
<div id="left">
<p>4:30pm - close (kitchen closes at 11pm)</p>
</div>
<div id="centre">
<a href="" target="_blank">Facebook</a>
<a href="" target="_blank">Instagram</a>
<a href="" target="_blank">Twitter</a>
</div>
<div id="right">
<p>64 Welfare Road, Cole Bay, Sint Maarten</p>
</div>
<!---
This is an option button that will pause the video background
<div>
<button>Pause</button>
</div>
--->
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="js/index.js"></script>
</body>
</html>
CSS:
#left{
position: absolute;
float: left;
bottom: 0;
left: 20px;
color: white;
}
#centre{
position: absolute;
float: left;
margin-left: 40%;
bottom: 10px;
clear: inherit;
min-width: 300px;
}
#right{
position: absolute;
float: left;
margin-left: 78%;
bottom: 0;
color: white;
}
@media screen and (max-width: 500px) {
div{display: block}
}
@media screen and (max-device-width: 800px) {
html { background: url(assets/backupimage.jpg) #000 no-repeat center center fixed; }
#bgvid { display: none; }
div{display: block}
}
答案 0 :(得分:1)
绝对定位是页面布局的不良选择。使用浮动或弹性框。
main,
footer > div {
text-align: center;
font-family: Roboto, sans-serif;
}
main {
min-height: 300px;
color: #f1f1f1;
background-color: #333;
font-size: 2.5rem;
}
main strong {
text-decoration: underline;
}
footer > div:nth-child( 2 ) {
background-color: #eee;
}
@media ( min-width: 450px ) {
footer > div {
float: left;
width: 33.333%;
}
}
<main>
<strong>Floated</strong> footer sections.
</main>
<footer>
<div>One</div>
<div>Two</div>
<div>Three</div>
</footer>
main,
footer > div {
text-align: center;
font-family: Roboto, sans-serif;
}
main {
min-height: 300px;
color: #f1f1f1;
background-color: #333;
font-size: 2.5rem;
}
main strong {
text-decoration: underline;
}
footer {
display: flex;
flex-direction: column;
}
footer > div {
flex: 1;
}
footer > div:nth-child( 2 ) {
background-color: #eee;
}
@media ( min-width: 450px ) {
footer {
flex-direction: row;
}
}
<main>
<strong>Flex</strong> footer sections.
</main>
<footer>
<div>One</div>
<div>Two</div>
<div>Three</div>
</footer>
答案 1 :(得分:1)
我同意hungerstar的评论 - 绝对定位将使您的网页响应变得不必要。话虽如此,它可以做到。您已经在CSS中使用了@media屏幕和(max-width:500px)语法,但没有在其功能的全部范围内使用它。在标记为max-width:500px部分的部分内部,您有机会完全重新定义css以获得小于500px的浏览器窗口。在这些括号内,您可以重新定义3个div的CSS。
@media screen and (max-width: 500px){
#left{
position: absolute;
float: left;
bottom: 200px;
left: 20px;
color: white;
}
#centre{
position: absolute;
left: 20px;
float: left;
bottom: 100px;
clear: inherit;
min-width: 300px;
}
#right{
position: absolute;
float: left;
left: 20px;
bottom: 0;
color: white;
}
}
所以这将检查你的屏幕宽度,当它变得小于500px时,这个CSS将被应用,你的3个div将被重新定位到左边,堆叠在一起(我组成)任意位置(从底部100和200像素)。你需要为800px大小的屏幕重新定义所有这些
答案 2 :(得分:0)
您使用position:absolute
你需要做这样的事情:
#left {
float: left;
color: white;
}
#centre {
float: left;
clear: inherit;
min-width: 300px;
}
#right {
float: left;
color: white;
}
这是fiddle