Gia*_*ini 15 html css stylesheet hyperlink
我有一个div,我想覆盖我的全局链接样式.我有两种链接样式,一种是全局的,一种是特定的.这里的代码:
A:link {text-decoration: none; color: #FF0000;}
A:visited {text-decoration: none; color: #FF0000;}
A:hover {text-decoration: none; color: #FF0000;}
A:active {text-decoration: none; color: #FF0000;}
#macrosectiontext
{
position:relative;
font:Arial, sans-serif;
text-align:center;
font-size:50px;
font-style: bold;
margin-top:245px;
opacity: 0.6;
background-color:transparent;
}
#macrosectiontext A:link {text-decoration: none; color: #000000;}
#macrosectiontext A:visited {text-decoration: none; color: #FFFFFF;}
#macrosectiontext A:hover {text-decoration: none; color: #FFFFFF;}
#macrosectiontext A:active {text-decoration: none; color: #FFFFFF;}
Run Code Online (Sandbox Code Playgroud)
我使用这样的div:
<div id="macrosectiontext"><a href="www.google.it">bla bla bla</a></div>
Run Code Online (Sandbox Code Playgroud)
但似乎它不起作用.div仍然继承了全局链接样式.
Mar*_*ark 10
CSS处理继承,因此您应该只覆盖要更改的属性.
尝试始终写HTML和CSS小写,仍然你的HTML和CSS是正确的
a:link, a:visited, a:hover, a:active {
text-decoration: none; color: #f00;
}
#macrosectiontext {
position:relative;
font:Arial, sans-serif;
text-align:center;
font-size:50px;
font-style: bold;
margin-top:245px;
opacity: 0.6;
background-color:transparent;
}
#macrosectiontext a:link {color: #000;}
#macrosectiontext a:visited, #macrosectiontext a:hover,
#macrosectiontext a:active {
color: #fff;
}
Run Code Online (Sandbox Code Playgroud)
我为你做了一个小提示,以显示你的代码是否有效(改变了悬停颜色,仅用于演示)
小智 8
在css我不会使用id"#macrosectiontext a:link ..."作为链接代码,我会使用类".macrosectiontext"
在链接样式中使用小写"a"而不是Cap"A"
如果您只使用该样式几次,则可以在链接周围使用span标记,然后从span标记中调用您的样式而不是div.