gpt4 book ai didi

html - CSS 类无效

转载 作者:行者123 更新时间:2023-11-28 14:50:17 26 4
gpt4 key购买 nike

长话短说

这是我的 CSS 代码和 HTML 代码

<div class="navbar">
<nav>
<span id="logo">
<a href="index.html">Logo</a>
</span>
<ul class="menu">
<li><a href="#home">Home</a></li>
<li><a href="#about">About Me</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
<div id="toggle">
<div class="span" id="one"></div>
<div class="span" id="two"></div>
<div class="span" id="three"></div>
</div>
</nav>
</div>

CSS:

 * {
margin: 0;
padding: 0;
text-decoration: none;
list-style: none;
}

结果:https://imgur.com/a/c6rWS3V (第二张图)

如果我将 * 换成 .navbar 类,那么我会得到以下结果(图 2,谢谢!) https://imgur.com/a/c6rWS3V (第一张图片)

下面是长版本:(如果将 * 换成 .navbar,它将不起作用)问题是为什么?

* {
margin: 0;
padding: 0;
text-decoration: none;
list-style: none;
}

nav {
width: 100%;
background: #000;
height: 70px;
position: static;
z-index: 1;
}

nav #logo {
float: left;
display: block;
margin-left: 84px;
font-size: 30px;
line-height: 70px;
font-weight: bold;
}

nav #logo a {
color: #fff;
transition: all 0.3s ease-out;
font-family: 'Poppins', sans-serif;
font-weight: 300;
}

nav .menu {
float: left;
left: 50%;
position: relative;
}

nav .menu li {
display: inline-block;
padding: 0px 30px;
cursor: pointer;
line-height: 70px;
position: relative;
transition: all 0.3s ease-out;
}

nav .menu li a {
color: #fff;
font-family: 'Poppins', sans-serif;
font-weight: 200;
}

#toggle {
position: absolute;
right: 20px;
top: 14px;
z-index: 999;
width: 40px;
height: 40px;
cursor: pointer;
float: right;
transition: all 0.3s ease-out;
visibility: hidden;
opacity: 0;
}

#toggle .span {
height: 3px;
background: #fff;
transition: all 0.3s ease-out;
backface-visibility: hidden;
margin: 5px auto;
}

#toggle.on #one {
transform: rotate(45deg) translateX(2px) translateY(4px);
}

#toggle.on #two {
opacity: 0;
}

#toggle.on #three {
transform: rotate(-45deg) translateX(8px) translateY(-10px);
}


@media(max-width: 768px) {
#toggle {
visibility: visible;
opacity: 1;
margin-top: 6px;
}
nav #logo {
margin-left: 18px;
}
.menu a {
font-family: 'Poppins', sans-serif;
font-weight: 200;
font-size: 20px;
}
nav .menu {
display: none;
}
}
@media only screen and (max-width: 1366px) and (min-width: 1024px)
{
.menu a {
position: relative;
margin-left: -30px;
font-size: 2vw;
}
}
@media only screen and (width: 812px) and (min-width: 375px)/* IPHONE X */
{
.menu a {
position: relative;
margin-left: -80px;
font-size: 2vw;
}
}
@media only screen and (width: 823px) and (min-width: 411px) /*GOOGLE PIXEL 2XL */
{
.menu a {
position: relative;
margin-left: -120px;
font-size: 2vw;
}
}
 <div class="navbar">
<nav>
<span id="logo">
<a href="index.html">Logo</a>
</span>
<ul class="menu">
<li><a href="#home">Home</a></li>
<li><a href="#about">About Me</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
<div id="toggle">
<div class="span" id="one"></div>
<div class="span" id="two"></div>
<div class="span" id="three"></div>
</div>
</nav>
</div>

谢谢!p.s 我尽量用这个编辑器,还是新的!虽然我认为我做得“不错”:D

最佳答案

始终将 text-decoration:none 添加到 a 标签

.navbar #logo a{
text-decoration:none;
}

*{
css rules
}

应用于所有内容(包括 a 标记),这就是为什么您没有为 Logo 添加下划线的原因。

* {
margin: 0;
padding: 0;
/* text-decoration: none;*/ /* Comeented for sake of answer*/
list-style: none;
}

nav {
width: 100%;
background: #000;
height: 70px;
position: static;
z-index: 1;
}

nav #logo {
float: left;
display: block;
margin-left: 84px;
font-size: 30px;
line-height: 70px;
font-weight: bold;
}

nav #logo a {
color: #fff;
transition: all 0.3s ease-out;
font-family: 'Poppins', sans-serif;
font-weight: 300;
}

nav .menu {
float: left;
left: 50%;
position: relative;
}

nav .menu li {
display: inline-block;
padding: 0px 30px;
cursor: pointer;
line-height: 70px;
position: relative;
transition: all 0.3s ease-out;
}

nav .menu li a {
color: #fff;
font-family: 'Poppins', sans-serif;
font-weight: 200;
}

#toggle {
position: absolute;
right: 20px;
top: 14px;
z-index: 999;
width: 40px;
height: 40px;
cursor: pointer;
float: right;
transition: all 0.3s ease-out;
visibility: hidden;
opacity: 0;
}

#toggle .span {
height: 3px;
background: #fff;
transition: all 0.3s ease-out;
backface-visibility: hidden;
margin: 5px auto;
}

#toggle.on #one {
transform: rotate(45deg) translateX(2px) translateY(4px);
}

#toggle.on #two {
opacity: 0;
}

#toggle.on #three {
transform: rotate(-45deg) translateX(8px) translateY(-10px);
}


@media(max-width: 768px) {
#toggle {
visibility: visible;
opacity: 1;
margin-top: 6px;
}
nav #logo {
margin-left: 18px;
}
.menu a {
font-family: 'Poppins', sans-serif;
font-weight: 200;
font-size: 20px;
}
nav .menu {
display: none;
}
}
@media only screen and (max-width: 1366px) and (min-width: 1024px)
{
.menu a {
position: relative;
margin-left: -30px;
font-size: 2vw;
}
}
@media only screen and (width: 812px) and (min-width: 375px)/* IPHONE X */
{
.menu a {
position: relative;
margin-left: -80px;
font-size: 2vw;
}
}
@media only screen and (width: 823px) and (min-width: 411px) /*GOOGLE PIXEL 2XL */
{
.menu a {
position: relative;
margin-left: -120px;
font-size: 2vw;
}
}

.navbar #logo a{
text-decoration:none;
}
<div class="navbar">
<nav>
<span id="logo">
<a href="index.html">Logo</a>
</span>
<ul class="menu">
<li><a href="#home">Home</a></li>
<li><a href="#about">About Me</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
<div id="toggle">
<div class="span" id="one"></div>
<div class="span" id="two"></div>
<div class="span" id="three"></div>
</div>
</nav>
</div>

关于html - CSS 类无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51753611/

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