我已将代码发布在我的代码笔上。我想做的是将黄色内容框移到导航链接后面。我有两个不同的导航栏。一种用于移动设备,另一种用于桌面设备。在台式机和移动设备上单击下拉菜单时,它们似乎位于内容DIV的后面。我已经尝试了一些没有运气的事情。这个网站是实验性的,但我只是被卡住了。任何帮助将非常感激。如果您需要更多信息,请询问。谢谢..
链接: Codepen
代码:
body {
background-color: #000;
overflow: hidden;
font-family: Georgia, "Times New Roman", serif;
font-family: helvetica, sans-serif;
margin: 0;
padding: 0;
}
@media only screen and (max-width: 711px) {
.linkwrapm {
background-color: #fff;
height: 50px;
margin-top: -16;
width: 100%;
text-align: left;
padding-top: 11px;
}
.centerm {
position: absolute;
left: 45%;
top: 14%;
;
}
.bannerm {
background-color: #fff;
height: 58px;
padding-top: 9px;
padding-bottom: 19px;
background-size: 300px 60px;
background-repeat: no-repeat;
}
.navbartextm {
background-color: #fff;
color: grey;
font-size: 27px;
text-align: left;
padding-left: 12px;
font-weight: bold;
}
/* mobile menu*/
.navm {
padding-left: 45px;
font-weight: bold;
text-align: left;
margin: 0;
padding-top: 8px;
padding-bottom: 9px;
background-color: #eeeeee;
color: black;
font-size: 20px;
}
/*Func*/
.multi-level,
.item ul,
.nav input[type="checkbox"] {
display: none;
}
#menu:checked~.multi-level,
.item input:checked~ul {
display: block;
}
/*Arrow*/
.arrow {
width: 12px;
height: 12px;
vertical-align: middle;
float: left;
z-index: 0;
margin: 17px 1em 0 2em;
}
.item input+.arrow {
transform: rotate(-810deg);
/*default 90deg*/
transition: 0.4s;
/*Default 2s*/
}
.item input:checked+.arrow {
transform: rotate(0deg);
transition: 0.2s;
}
/*Styles*/
label:hover {
cursor: pointer;
color: black;
font-size: 20px;
}
label {
width: 100%;
display: block;
z-index: 3;
position: relative;
font-size: 20px;
}
.nav {
width: 68%;
background-color: white;
overflow-x: hidden;
}
#nav-icon {
font-size: 45px;
line-height: 50px;
padding-left: 2em;
color: black;
background-color: #fff;
}
#nav-icon:hover {
color: #A9A9A9;
}
.nav ul,
.nav li,
label {
line-height: 40px;
margin: 0;
padding: 0 -1em;
list-style: none;
text-decoration: none;
color: #A9A9A9;
font-weight: 100;
width: 100%;
}
.item ul {
padding: 0 0.25em;
border-bottom: 1px solid gray;
}
.nav li a {
line-height: 50px;
margin: 0;
padding: 0 4em;
list-style: none;
text-decoration: none;
color: #000000;
font-weight: 100;
}
.nav li a:hover {
color: #A9A9A9;
}
/* mobile menu end*/
.banner {
display: none !important;
}
/* Full Dropdown Hide */
.dropdown {
display: none !important;
}
.dd-button {
display: none !important;
}
.dd-button:after {
display: none !important;
}
.dd-button:hover {
display: none !important;
}
.dd-input {
display: none !important;
}
.dd-menu {
display: none !important;
}
.dd-input+.dd-menu {
display: none !important;
}
.dd-input:checked+.dd-menu {
display: none !important;
}
.dd-menu li {
display: none !important;
}
.dd-menu li:hover {
display: none !important;
}
.dd-menu li a {
display: none !important;
}
.dd-menu li.divider {
display: none !important;
}
/* Full Dropdown Hide End */
}
@media only screen and (min-width: 712px) {
.linkwrapm {
display: none !important;
}
.bannerm {
display: none !important;
}
.linkwrap {
background-color: #fff;
height: 50px;
margin-top: -20px;
width: 100%;
text-align: left;
padding-top: 10px;
}
.banner {
background-color: #fff;
height: 60px;
padding-top: 15px;
padding-bottom: 20px;
}
/* Full Navigation*/
a {
text-decoration: none;
color: #000000;
}
a:hover {
color: #222222;
}
/* Dropdown */
.dropdown {
display: inline-block;
position: relative;
margin-left: 10;
}
.dd-button {
display: inline-block;
border: 1px solid gray;
border-radius: 4px;
padding: 10px 30px 10px 20px;
background-color: #ffffff;
cursor: pointer;
white-space: nowrap;
}
.dd-button:after {
content: '';
position: absolute;
top: 50%;
right: 20px;
transform: translateY(-50%);
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid black;
}
.dd-button:hover {
background-color: #eeeeee;
}
.dd-input {
display: none;
}
.dd-menu {
position: absolute;
top: 100%;
border: 1px solid #ccc;
border-radius: 4px;
padding: 0;
margin: 2px 0 0 0;
box-shadow: 0 0 6px 0 rgba(0, 0, 0, 0.1);
background-color: #ffffff;
list-style-type: none;
}
.dd-input+.dd-menu {
display: none;
}
.dd-input:checked+.dd-menu {
display: block;
}
.dd-menu li {
padding: 10px 20px;
cursor: pointer;
white-space: nowrap;
}
.dd-menu li:hover {
background-color: #f6f6f6;
}
.dd-menu li a {
display: block;
margin: -10px -20px;
padding: 10px 20px;
}
.dd-menu li.divider {
padding: 0;
border-bottom: 1px solid #cccccc;
}
/* Full Navigation*/
}
/* CONTENT*/
.wrapper {
background-color: yellow;
z-index: 1;
position: absolute;
left: 0;
right: 0;
height: 120px;
color: white;
padding: 0;
}
.content {
background-color: yellow;
width: 23px;
clear: both;
}
/* CONTENT*/
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src "script.js">
</script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="banner">
<img border="0" alt="" src="placeholder.png" width="300" height="60" align="left" hspace="20">
</div>
<div class="bannerm">
<img border="0" alt="" src="placeholder.png" width="300" height="60" align="left" hspace="20">
</div>
<div class="linkwrapm">
<div class="nav">
<input type="checkbox" id="menu" />
<label for="menu" id="nav-icon">☰</label>
<div class="multi-level">
<div class="item">
<br>
<div class="navm">Navigation </div>
<BR>
<input type="checkbox" id="A" />
<img src="images/Arrow.png" class="arrow"><label for="A">Services</label>
<ul>
<li><a href="#">Branding</a></li>
<li><a href="#">Web/App Development</a></li>
<li><a href="#">Internet Marketing and SEO</a></li>
</ul>
</div>
<div class="item">
<input type="checkbox" id="B" />
<img src="images/Arrow.png" class="arrow"><label for="B">Jobs</label>
<ul>
<li>
<div class="sub-item">
<input type="checkbox" id="B-A" />
</div>
</li>
<li>
<div class="sub-item">
<input type="checkbox" id="B-B" />
</div>
</li>
<li><a href="#">Graphic Designer</a></li>
<li><a href="#">Logo Designer</a></li>
</ul>
</div>
<div class="item">
<input type="checkbox" id="C" />
<img src="images/Arrow.png" class="arrow"><label for="C">About Us</label>
<ul>
<li><a href="#">Our Team</a></li>
<li><a href="#">Clients</a></li>
<li><a href="#">Our Work</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="linkwrap">
<label class="dropdown">
<div class="dd-button">
Dropdown
</div>
<input type="checkbox" class="dd-input" id="test">
<ul class="dd-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>
<a href="linkhere">Link to Rane.io</a>
</li>
</ul>
</label>
<label class="dropdown">
<div class="dd-button">
Dropdown
</div>
<input type="checkbox" class="dd-input" id="test">
<ul class="dd-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>
<a href="linkhere">Link to Rane.io</a>
</li>
</ul>
</label>
<label class="dropdown">
<div class="dd-button">
Dropdown
</div>
<input type="checkbox" class="dd-input" id="test">
<ul class="dd-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>
<a href="linkhere">Link to Rane.io</a>
</li>
</ul>
</label>
<label class="dropdown">
<div class="dd-button">
Dropdown
</div>
<input type="checkbox" class="dd-input" id="test">
<ul class="dd-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>
<a href="linkhere">Link to Rane.io</a>
</li>
</ul>
</label>
<label class="dropdown">
<div class="dd-button">
Dropdown
</div>
<input type="checkbox" class="dd-input" id="test">
<ul class="dd-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>
<a href="linkhere">Link to Rane.io</a>
</li>
</ul>
</label>
</div>
<div class="wrapper">
hi
</div>
<div class="content">
</div>
<script type="text/javascript" src="script.js"></script>
</body>
</html>
.wrapper{
width: 100vw;
background-color:yellow;
z-index: -10;
position: absolute;
margin: 0 auto;
height: 120px;
color: white;
padding: 0;
}
body { background-color:#000; overflow:hidden; font-family: Georgia, "Times New Roman", serif; font-family: helvetica, sans-serif; margin: 0; padding: 0; } @media only screen and (max-width: 711px) { .linkwrapm{ background-color:#fff; height:50px; margin-top: -16; width:100%; text-align:left; padding-top:11px; } .centerm{ position: absolute; left: 45%; top: 14%;; } .bannerm{ background-color:#fff; height:58px; padding-top: 9px; padding-bottom:19px; background-size: 300px 60px; background-repeat: no-repeat; } .navbartextm{ background-color:#fff; color:grey; font-size:27px; text-align:left; padding-left:12px; font-weight: bold; } /* mobile menu*/ .navm{ padding-left:45px; font-weight: bold; text-align:left; margin:0; padding-top:8px; padding-bottom:9px; background-color:#eeeeee; color:black; font-size:20px; } /*Func*/ .multi-level, .item ul, .nav input[type="checkbox"] { display: none; } #menu:checked ~ .multi-level, .item input:checked ~ ul { display: block; } /*Arrow*/ .arrow { width: 12px; height: 12px; vertical-align: middle; float: left; z-index: 0; margin: 17px 1em 0 2em; } .item input + .arrow { transform: rotate(-810deg); /*default 90deg*/ transition: 0.4s; /*Default 2s*/ } .item input:checked + .arrow { transform: rotate(0deg); transition: 0.2s; } /*Styles*/ label:hover { cursor: pointer; color:black; font-size:20px; } label { width: 100%; display: block; z-index: 3; position: relative; font-size:20px; } .nav { width: 68%; background-color: white; overflow-x: hidden; } #nav-icon { font-size: 45px; line-height: 50px; padding-left: 2em; color: black; background-color: #fff; } #nav-icon:hover { color: #A9A9A9; } .nav ul, .nav li, label { line-height: 40px; margin: 0; padding: 0 -1em; list-style: none; text-decoration: none; color: #A9A9A9; font-weight: 100; width: 100%; } .item ul { padding: 0 0.25em; border-bottom:1px solid gray; } .nav li a { line-height: 50px; margin: 0; padding: 0 4em; list-style: none; text-decoration: none; color: #000000; font-weight: 100; } .nav li a:hover{ color: #A9A9A9; } /* mobile menu end*/ .banner { display: none !important; } /* Full Dropdown Hide */ .dropdown { display: none !important; } .dd-button { display: none !important; } .dd-button:after { display: none !important; } .dd-button:hover { display: none !important; } .dd-input { display: none !important; } .dd-menu { display: none !important; } .dd-input + .dd-menu { display: none !important; } .dd-input:checked + .dd-menu { display: none !important; } .dd-menu li { display: none !important; } .dd-menu li:hover { display: none !important; } .dd-menu li a { display: none !important; } .dd-menu li.divider{ display: none !important; } /* Full Dropdown Hide End */ } @media only screen and (min-width: 712px) { .linkwrapm{ display: none !important; } .bannerm{ display: none !important; } .linkwrap{ background-color:#fff; height:50px; margin-top: -20px; width:100%; text-align:left; padding-top:10px; } .banner{ background-color:#fff; height:60px; padding-top: 15px; padding-bottom:20px; } /* Full Navigation*/ a { text-decoration: none; color: #000000; } a:hover { color: #222222; } /* Dropdown */ .dropdown { display: inline-block; position: relative; margin-left:10; } .dd-button { display: inline-block; border: 1px solid gray; border-radius: 4px; padding: 10px 30px 10px 20px; background-color: #ffffff; cursor: pointer; white-space: nowrap; } .dd-button:after { content: ''; position: absolute; top: 50%; right: 20px; transform: translateY(-50%); width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 5px solid black; } .dd-button:hover { background-color: #eeeeee; } .dd-input { display: none; } .dd-menu { position: absolute; top: 100%; border: 1px solid #ccc; border-radius: 4px; padding: 0; margin: 2px 0 0 0; box-shadow: 0 0 6px 0 rgba(0,0,0,0.1); background-color: #ffffff; list-style-type: none; } .dd-input + .dd-menu { display: none; } .dd-input:checked + .dd-menu { display: block; } .dd-menu li { padding: 10px 20px; cursor: pointer; white-space: nowrap; } .dd-menu li:hover { background-color: #f6f6f6; } .dd-menu li a { display: block; margin: -10px -20px; padding: 10px 20px; } .dd-menu li.divider{ padding: 0; border-bottom: 1px solid #cccccc; } /* Full Navigation*/ } /* CONTENT*/ .wrapper{ width: 100vw; background-color:yellow; z-index: -10; position: absolute; margin: 0 auto; height: 120px; color: white; padding: 0; } .content { background-color:yellow; width:23px; clear:both; } /* CONTENT*/
<link rel="stylesheet" href="master.css"> <html> <head> <link rel="stylesheet" href="style.css"> <script src"script.js"> </script> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <div class="banner"> <img border="0" alt="" src="placeholder.png" width="300" height="60" align="left" hspace="20"> </div> <div class="bannerm"> <img border="0" alt="" src="placeholder.png" width="300" height="60" align="left" hspace="20"> </div> <div class="linkwrapm"> <div class="nav"> <input type="checkbox" id="menu"/> <label for="menu" id="nav-icon">☰</label> <div class="multi-level"> <div class="item"> <br> <div class="navm">Navigation </div><BR> <input type="checkbox" id="A"/> <img src="images/Arrow.png" class="arrow"><label for="A">Services</label> <ul> <li><a href="#">Branding</a></li> <li><a href="#">Web/App Development</a></li> <li><a href="#">Internet Marketing and SEO</a></li> </ul> </div> <div class="item"> <input type="checkbox" id="B"/> <img src="images/Arrow.png" class="arrow"><label for="B">Jobs</label> <ul> <li><div class="sub-item"> <input type="checkbox" id="B-A"/> </div></li> <li><div class="sub-item"> <input type="checkbox" id="B-B"/> </div></li> <li><a href="#">Graphic Designer</a></li> <li><a href="#">Logo Designer</a></li> </ul> </div> <div class="item"> <input type="checkbox" id="C"/> <img src="images/Arrow.png" class="arrow"><label for="C">About Us</label> <ul> <li><a href="#">Our Team</a></li> <li><a href="#">Clients</a></li> <li><a href="#">Our Work</a></li> </ul> </div> </div> </div> </div> <div class="linkwrap"> <label class="dropdown"> <div class="dd-button"> Dropdown </div> <input type="checkbox" class="dd-input" id="test"> <ul class="dd-menu"> <li>Action</li> <li>Another action</li> <li>Something else here</li> <li class="divider"></li> <li> <a href="linkhere">Link to Rane.io</a> </li> </ul> </label> <label class="dropdown"> <div class="dd-button"> Dropdown </div> <input type="checkbox" class="dd-input" id="test"> <ul class="dd-menu"> <li>Action</li> <li>Another action</li> <li>Something else here</li> <li class="divider"></li> <li> <a href="linkhere">Link to Rane.io</a> </li> </ul> </label> <label class="dropdown"> <div class="dd-button"> Dropdown </div> <input type="checkbox" class="dd-input" id="test"> <ul class="dd-menu"> <li>Action</li> <li>Another action</li> <li>Something else here</li> <li class="divider"></li> <li> <a href="linkhere">Link to Rane.io</a> </li> </ul> </label> <label class="dropdown"> <div class="dd-button"> Dropdown </div> <input type="checkbox" class="dd-input" id="test"> <ul class="dd-menu"> <li>Action</li> <li>Another action</li> <li>Something else here</li> <li class="divider"></li> <li> <a href="linkhere">Link to Rane.io</a> </li> </ul> </label> <label class="dropdown"> <div class="dd-button"> Dropdown </div> <input type="checkbox" class="dd-input" id="test"> <ul class="dd-menu"> <li>Action</li> <li>Another action</li> <li>Something else here</li> <li class="divider"></li> <li> <a href="linkhere">Link to Rane.io</a> </li> </ul> </label> </div> <div class="wrapper"> hi </div> <div class="content"> </div> <script type="text/javascript" src="script.js"></script> </body> </html>
旧答案将位置设置为绝对位置,并在顶部做边距:-元素的高度该代码难以理解,并且类和id的命名使理解任何东西变得非常困难。另外,您还没有提供有关要更改哪些类和/或ID的信息,这使操作更加困难。
[我还将提到您的响应式设计方法是非常不合常规的。但是我想我知道了。
所以可以说这是您想要在最上面一行后面的
wrapper
.wrapper{ width: 100vw; height: 120px; position: absolute; margin-top: -120px; color: white; }
现在,它阻止了所有操作,您希望它落在后面。要获得该功能,您必须将带有类包装器的部门移到顶部。
<body> <div class="wrapper"> hi </div>
现在应该在您想要的位置。但现在您看不到它。现在,如果要使其可见,则必须将背景色设置为透明,例如使用RGBA
background-color:rgb(255, 255, 255, .0);
应该这样做。为我工作!
旧更新
这里是白色div与蓝色重叠的示例
body { background: #333; } .header { border: 25px solid red; height: 30vh; background: rgba(0, 0, 255, .75); /*blue*/ } .wrapper { border: 25px solid lime; height: 30vh; background: rgba(255, 255, 255, .75); /*white*/ margin-top: -15vh; /* half way overlapping*/ }
<body> <div class="header"> </div> <div class="wrapper"> </div> </body>
现在注意,当我将html标签移动到包装位于顶部而不是标头的位置时会发生什么!body { background: #333; } .header { border: 25px solid red; height: 30vh; background: rgba(0, 0, 255, .5); /*blue*/ margin-top: -15vh; /* half way overlapping*/ } .wrapper { border: 25px solid lime; height: 30vh; background: rgba(255, 255, 255, .5); /*white*/ }
<body> <div class="wrapper"> </div> <div class="header"> </div> </body>
注意我如何也将边距顶部的位置从.wrapper更改为.header