Css 将样式应用于所有链接元素
我不确定这在wordpress中是否可行,但我需要通过在style.css中添加代码来设置主题中所有Css 将样式应用于所有链接元素,css,wordpress,Css,Wordpress,我不确定这在wordpress中是否可行,但我需要通过在style.css中添加代码来设置主题中所有元素的样式 样式需要应用于所有链接,除了按钮和放置菜单的标题部分中的链接。下面的代码不起作用 a:link { color: red; text-decoration: none; text-transform: uppercase; } a:hover { color: blue; text-decoration: none; text-transform: upperc
元素的样式
样式需要应用于所有链接,除了按钮和放置菜单的标题部分中的链接。下面的代码不起作用
a:link {
color: red;
text-decoration: none;
text-transform: uppercase;
}
a:hover {
color: blue;
text-decoration: none;
text-transform: uppercase;
}
a:active{
color: purple;
text-decoration: none;
text-transform: uppercase;
}
您可以使用一些JavaScript() 如果您知道标题或菜单的类名,这将起作用 并使用这个CSS
.my-link {
color: red;
text-decoration: none;
text-transform: uppercase;
}
.my-link:hover {
color: blue;
text-decoration: none;
text-transform: uppercase;
}
.my-link:active{
color: purple;
text-decoration: none;
text-transform: uppercase;
}
你的CSS可能不起作用,因为你的WordPress主题已经包含了一些链接的CSS规则,所以它优先于你的规则 您需要在目标元素中更加具体,例如:
a{}
a、 某些类{}/*更具体*/
body a.some-class{}/*更具体*/
特异性是浏览器决定哪些CSS属性值与元素最相关并因此应用的方法。[…]特异性是应用于给定CSS声明的权重,由匹配选择器中每个选择器类型的数量确定。当多个声明具有相同的特异性时,CSS中找到的最后一个声明将应用于元素
-
此外,如果您使用的是子主题,请确保您的样式表在(父)主题的样式表之后排队
将父主题样式设置为子主题样式表的依赖项将确保子主题样式表在其之后加载
该官员举了一个例子:
“下面的代码不起作用”-它是否正确设置了任何链接的样式?它设置了所有链接的样式,甚至是wp仪表板:)但我需要为标题和按钮设置例外…好的,请查看我的答案并进行修改。我认为它有效。您必须使用JavaScript。
.my-link {
color: red;
text-decoration: none;
text-transform: uppercase;
}
.my-link:hover {
color: blue;
text-decoration: none;
text-transform: uppercase;
}
.my-link:active{
color: purple;
text-decoration: none;
text-transform: uppercase;
}
:not(button) a, :not(header) a {
/* links styling rules */
}