gpt4 book ai didi

html - 让 Div 标签扩展到页面底部,不覆盖页面上已有的元素

转载 作者:太空宇宙 更新时间:2023-11-04 12:47:17 24 4
gpt4 key购买 nike

我已经尝试绝对让我的页脚停留在页面底部,但它覆盖了已经在底部而不是在它们下面的元素。 Fixed 做类似的事情,除非页面更长,它会覆盖页面中心的元素。我实际上只是希望我的 div 的背景颜色延伸到页面底部,并让我的 Logo 和文本以设定的高度停留在 div 之间。这就是我得到的。

<!DOCTYPE html>
<html>
<head>

<link rel="stylesheet" type="text/css" href="main.css"/>
<title>

</title>

<div class="heading">
<img src="Images/Redbird.gif" alt="Redbird" style="float:left; padding-left:15px; padding-top:15px; width:150px;height:90px">

<form>
Search:
<input type="search" name="Search" style="float:right;">
</form>
<br></br>
<button type="button" id="Login">Login</button>
<button type="button" id="Login">Create New Account</button>
<h1>Technology Blog</h1>
<a href="index.html">
<img src="Images/House.png" alt="Home" style="width:35px; height:35px;">
</a>
</div>

<div class="table">
<table style+"width:100%">
<tr>
<td><a href="phones.html">Phones & Tablets</a></td>
<td>Computers & Laptops</td>
<td>Internships</td>
<td>Troubleshooting</td>
<td>Product Ratings & Reviews</td>
</tr>
</table>
</div>
</head>

<body>
<div class="Welcome">
<h2>Welcome</h2>
<p>Welcome to Illinois State University's Technology Blog. Here you can view and post questions, answers, reviews, and other information that is related to technology. This website is for Illinois State University Students ONLY! You must sign in or create an account to view or post on this website.</p>
</div>
<div class="Slideshow">
<img src="Images/DellComps.jpg" alt="Computers" style="width: 397px; height: 298px">
</div>

</body>

<div class="Footer">

<img src="Images/Seal.png" alt="ISU Seal" style="width: 40px; height: 40px; padding-bottom: 10px; padding-top: 10px">

Copyright 2014 @ TEC 319 Group <br/> Illinois Sate University
</div>

</html>

这是 CSS。我只需要编辑我认为的 .Footer 标签

html{
height: 100%;
position: relative;
}
h1{
text-align: center;
font-family: impact;
font-style: italic;
}

.heading{
background-color: #CA0000;
height:150px;
}
td{
border:5px solid black;
text-align:center;
background-color:#790000;
color:white;
padding:10px;
font-family: helvetica;
font-style: italic;
font-size: 15px;
}
table{
width:100%
}
.table{
background-color:black;
height:53px;
}
form{
float:right;
}
button{
float:right;
}
.Slideshow img{
display: block;
position: center;
margin-left: auto;
margin-right: auto;
}
.Footer img{
display: block;
position: center;
margin-left: auto;
margin-right: auto;
}
.Footer{
margin-top: 40px;
text-align: center;
background-color: #D8D8D8;
padding-bottom: 20px;
width: 100%;
}


.Preview td{
display: block;
text-align: left;
color: black;
background-color: white;

}
.Blog td{
display: block;
text-align: left;
color: black;
background-color: white;
border: 0px;

}
.newPost h2{
display: block;
position: center;
margin-left:auto;
margin-right: auto;
vertical-align: middle;
color: white;
background-color: #790000;
border: 5px solid black;
border-collapse: collapse;
width: 250px;
text-align: center;
}
h3 {
color: white;
background-color: #790000;
border: 5px solid black;

}
h4{
text-align: left;
font-size: 14pt;
color:#790000
}
.back h2{
display: block;
position: left;
border:5px solid black;
background-color:#790000;
color:white;
padding:10px;
font-family: helvetica;
font-style: italic;
font-size: 15px;
width: 100px;
}

form.comment{
float:left;
size
}
a.blogTitle:link {
color: #790000;
text-decoration: none;
}
a.blogTitle:visited{
color: #790000;
text-decoration: none;
}
a.blogTitle:active{
color: #790000;
text-decoration: none;
}
a.blogTitle:hover{
color: #CA0000;
text-decoration: none;
}
a:link {
color: white;
text-decoration: none;
}
a:visited{
color: white;
text-decoration: none;
}
a:active{
color: white;
text-decoration: none;
}
a:hover{
color: #CA0000;
text-decoration: none;
}

最佳答案

您需要将页脚位置设置为 relative 以使其尊重页面上的其他元素。 absolutefixed 都会从页面流中移除元素,这会导致重叠。

Demo

在演示 CSS 中将 position:relative 更改为 fixed,然后取消注释 bottom 以查看差异。您还可以使用 body 标签上的 height 来查看行为如何变化。

<div id="content">
<p>Content</p>
</div>
<div id="footer">
<p>Footer stuff</p>
</div>

body {
margin:0;
padding:0;
}
#content {
height:1200px;
width:100px;
background-color:#eee;
position:relative;
margin:0;
padding:0;
border:1px solid black;
}
#footer {
width:100px;
position:relative;
/* bottom:0; */
background-color:#eee;
margin:0;
padding:0;
border:1px solid black;
}

关于html - 让 Div 标签扩展到页面底部,不覆盖页面上已有的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26412082/

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