首页 > 解决方案 > 如何更改文字样式?

问题描述

我有一个黑色的基本可点击文本,我想让另一个文本变成绿色,但如果我改变它,黑色的文本会改变

我怎样才能做到这一点?

a {
  color: black;
  font-size: 40px;
  font-weight: bold;
  text-decoration: none;
}
<p class="margin-ot"><a href="file:///...index.html">Reviews from past exams</a></p>

标签: htmlcss

解决方案


给你想要绿色的元素一个特定的类,然后使用那个类来设置它的样式。请注意,我在原始样式下方声明了该样式,并在其旁边使用了类选择器以赋予其优先级。

以上所有内容都与CSS 选择器选择器特定性有关。我建议对所有那些非常重要的 CSS 概念进行研究。

此外,您可以将黑色文本的内部文本包装成一个跨度,然后按照您想要的方式对其进行样式设置。

a {
  color: black;
  font-size: 40px;
  font-weight: bold;
  text-decoration: none;
}

a.green{
 color: green;
}
a span{
 color: green;
}
<p class="margin-ot"><a href="file:///...index.html">Reviews from past exams</a></p>
<p class="margin-ot"><a href="file:///...index.html" class="green">Reviews from past exams</a></p>
<p class="margin-ot"><a href="file:///...index.html">Reviews from past<span> exams </span></a></p>


推荐阅读