gpt4 book ai didi

html - 如何将内容放在位置绝对元素下方

转载 作者:太空宇宙 更新时间:2023-11-04 01:59:26 26 4
gpt4 key购买 nike

我不确定如何提出这个问题,但我会尽力解释我想要完成的事情。我的主页上有一个横幅,在这个横幅内我有一个 div 与它重叠。

现在,通过将此元素重叠在横幅上会产生一个问题,即我主页上的所有其他内容都在这个重叠元素后面。示例:我的页脚(标记为红色)在这个重叠元素后面,我想要阻止这种情况发生,我希望所有内容都在它下面。

* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
color: #444;
font-size: 13px;
background-color: #fafafa;
font-family: Arial, sans-serif;
}

.container {
height: auto;
width: 1200px;
margin: 0 auto;
overflow: hidden;
}

secion {
width: 100%;
height: auto;
background-color: #fff;
}

header {
width: 100%;
height: 168px;
overflow: hidden;
box-shadow: 0 2px 5px 0 rgba(0,0,0,.16);
}

.top-nav {
width: 100%;
height: 42px;
background-color: white;
}

.top-nav ul {
float: left;
line-height: 42px;
list-style-type: none;
}

.top-nav ul li {
display: inline-block;
}

.top-nav ul li a, a:visited {
color: #444;
padding: 42px 12px;
text-decoration: none;
}

.top-nav ul li a:hover {
background-color: #fafafa;
}

.center-console {
width: 100%;
height: 80px;
background-color: #f4f4f4;
}

header nav {
width: 100%;
height: 46px;
background-color: #fff;
}

header nav ul {
float: left;
line-height: 46px;
list-style-type: none;
}

header nav ul li {
margin: 0;
display: inline-block;
}

header nav ul li a, a:visited {
color: #444;
padding: 46px 12px;
text-decoration: none;
color: rgba(0,0,0,.54);
}

header nav ul li a:hover {
color: #15c;
background-color: #fff;
box-shadow: 0 4px 8px 0 #dcdcdc;
}


.logo {
float: left;
width: 200px;
height: 50px;
margin-top: 15px;
background-color: #fff;
}

.center-console form {
float: right;
width: 400px;
height: 40px;
padding: 0 15px;
margin-top: 20px;
border-radius: 3px;
background-color: #fff;
}

.search-icon-small {
width: 18px;
height: 19px;
float: right;
margin-top: 11px;
background-repeat: no-repeat;
background-image: url("../images/search-icon-small.png");
}

header form input[type=text] {
border: 0;
width: 342px;
height: 40px;
outline: none;
background-color: #fff;
}


.shopping-cart {
width: 38px;
height: 32px;
float: right;
margin-top: 7px;
font-size: 25px;
background-repeat: no-repeat;
background-image: url("../images/shopping-cart.png");
background-position:bottom;
}

.item-count {
color: #fff;
width: 18px;
height: 18px;
float: right;
font-size: 10px;
line-height: 19px;
font-weight: bold;
border-radius: 50%;
text-align: center;
background-color: #4683ea;
}


/*** Homepage ***/

.banner {
width: 100%;
height: 480px;
background-color: #4387fd;
}

.banner form {
width: 880px;
height: 50px;
margin: 0 auto;
padding: 0 15px;
margin-top: 228px;
border-radius: 3px;
background-color: #fff;
}

.search-icon {
width: 30px;
height: 30px;
float: right;
margin-top: 10px;
background-repeat: no-repeat;
background-image: url("../images/search-icon.png");
}

.banner form input[type=text] {
border: 0;
width: 805px;
height: 50px;
outline: none;
background-color: #fff;
}

.featured-items {
width: 1200px;
height: 358px;
padding: 21px;
margin-top: 100px;
border-radius: 6px;
position: absolute;
overflow: hidden;
background-color: #fff;
}

.featured-items ul {
list-style-type: none;
}

.featured-items ul li {
float: left;
width: 214px;
height: 214px;
margin-right: 22px;
background-color: #f5f5f5;
}

.featured-items ul li:last-child {
margin: 0;
float: right;
}

footer {
width: 100%;
height: 400px;
margin-top: 80px;
overflow: hidden;
background-color: red;
}
<!DOCTYPE html>
<html>
<head>
<title>BasicOffer</title>
<link rel="stylesheet" type="text/css"href="css/main.css">
<link rel="stylesheet" href="css/font-awesome/css/font-awesome.min.css">
</head>

<body>
<header>
<nav class="top-nav">
<div class="container">
<ul>
<li><a href="#">Selling</a></li>
<li><a href="#">Help</a></li>
</ul>
<ul style="float:right;">
<li><a href="#">Account</a></li>
</ul>
</div>
</nav>
<div class="center-console">
<div class="container">
<div class="logo"></div>
<form>
<input type="text" placeholder="Search..">
<div class="search-icon-small"></div>
</form>
</div>
</div>
<nav>
<div class="container">
<ul>
<li><a href="#">Health & Beauty</a></li>
<li><a href="#">Household Supplies</a></li>
<li><a href="#">Baby & Toddler</a></li>
<li><a href="#">Home & Garden</a></li>
<li><a href="#">Electronics</a></li>
<li><a href="#">Pet Supplies</a></li>
</ul>
<div class="shopping-cart">
<div class="item-count">11</div>
</div>
</div>
</nav>
</header>
<div class="banner">
<div class="container">
<form>
<input type="text" placeholder="What are you looking for?">
<div class="search-icon"></div>
</form>
<div class="featured-items">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</div>
</div>
<footer>This will be the footer</footer>
</body>

</html>

设计:

enter image description here

谢谢,理查德。

最佳答案

而不是使用绝对位置。你可以试试

margin-top: -150px;
position: relative;

working example

关于html - 如何将内容放在位置绝对元素下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42037079/

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