如何在导航栏上方放置负z-index的徽标?
问题描述:
我试图将我的标志(我用CSS制作)放在导航栏上方。该徽标具有负Z指数。我试图修复它。但我仍然不知道如何解决它。当我加载代码时,它将徽标放置在导航栏上。任何人都可以帮我把标志放在导航栏上面吗?如何在导航栏上方放置负z-index的徽标?
HTML:
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="random.css">
</head>
<body>
<div class="logo">
<h1 class="neon" data-text="[Home page]">[Home page]</h1>
</div>
<div class="menubalk">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Portfolio</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</body>
</html>
CSS:
@import url('https://fonts.googleapis.com/css?family=Quicksand:300');
body {
background: url(bg.jpg);
background-size: cover;
font-family: 'Quicksand', sans-serif;
}
.neon {
display: block;
position: absolute;
left: 50%;
transform: translateX(-50%);
margin: 0;
margin-bottom: 50px;
padding: 0 20px;
font-size: 6em;
color: #fff;
text-shadow: 0 0 20px #ff005b;
}
.neon:after {
content: attr(data-text);
position: absolute;
top: 0;
left: 0;
padding: 0 20px;
z-index: -1;
color: #ff005b;
filter: blur(15px)
}
.neon:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #fe3a80;
z-index: -2;
opacity: .5;
filter: blur(40px);
}
ul {
display: block;
padding: 0;
font-family: Arial;
display: flex;
background: white;
}
ul li {
list-style: none;
padding: 10px 20px;
}
ul li a {
text-decoration: none;
text-transform: uppercase;
font-size: 2em;
color: #262626;
position: relative;
}
ul li a:before {
content: '';
width: 0px;
height: 5px;
background: #00bcd4;
position: absolute;
top: 100%;
left: 0;
transition: .5s;
}
ul li:hover a:before {
width: 50%;
transform: translateX(100%);
}
答
有position:absolute
上.neon需要它的DOM的流动,并把它上面的(在顶部)其他元素。如果没有它,你可以达到所需的居中。
解决您的问题,我做了以下内容:
- 更改.neon显示为 'inline-block的'
- 更改.neon位置 '相对'
- 更改.neon:内容后''(空)
- 移除z索引从.neon:后.neon的
- 更改的z索引:前-1
点击下面的“运行代码段”。
@import url('https://fonts.googleapis.com/css?family=Quicksand:300');
body {
background: url(bg.jpg);
background-size: cover;
font-family: 'Quicksand', sans-serif;
}
.neon {
display: inline-block;
position:relative;
left: 50%;
transform: translateX(-50%);
margin: 0;
margin-bottom: 50px;
padding: 0 20px;
font-size: 6em;
color: #fff;
text-shadow: 0 0 20px #ff005b;
}
.neon:after {
content: '';
position: absolute;
top: 0;
left: 0;
padding: 0 20px;
color: #ffffff;
filter: blur(15px)
}
.neon:before {
content: '';
position: absolute;
z-index:-1;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #fe3a80;
opacity: .5;
filter: blur(40px);
}
ul {
display: block;
padding: 0;
font-family: Arial;
display: flex;
background: white;
}
ul li {
list-style: none;
padding: 10px 20px;
}
ul li a {
text-decoration: none;
text-transform: uppercase;
font-size: 2em;
color: #262626;
position: relative;
}
ul li a:before {
content: '';
width: 0px;
height: 5px;
background: #00bcd4;
position: absolute;
top: 100%;
left: 0;
transition: .5s;
}
ul li:hover a:before {
width: 50%;
transform: translateX(100%);
}
<body>
<div class="logo">
<h1 class="neon">Logo</h1>
</div>
<div class="menubalk">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Portfolio</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</body>
试图迫使它和使用'!important'! –
我刚开始学习HTML和CSS。所以我不知道如何在我的代码中应用它。 – martin
'z-index:-1!重要的;'你想要它在你的导航栏下或在你的导航栏? –