html - 如何更改文字样式?
问题描述
我有一个黑色的基本可点击文本,我想让另一个文本变成绿色,但如果我改变它,黑色的文本会改变
我怎样才能做到这一点?
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>
解决方案
给你想要绿色的元素一个特定的类,然后使用那个类来设置它的样式。请注意,我在原始样式下方声明了该样式,并在其旁边使用了类选择器以赋予其优先级。
以上所有内容都与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>
推荐阅读
- javascript - mustache Handlebars.js 部分获取列表中的所有对象
- testing - 从 Prometheus 指标中减去值 x 以获得 Grafana“单一统计”并激活“Delta”?
- javascript - 笑话:导入的类“未定义”
- oracle - 在存储过程 (Oracle) 中按视图名称打开视图 SQL
- ios - ios设备上的recaptcha问题
- c# - 从 WPF 中的 ComboBox 获取值
- android - 如何从 AutoCompleteTextView 中的 id 获取字段?
- python - python pandas中if else语句的lambda函数
- android - 为 IntDef 字段分配错误值时,Android Studio 和 Lint 不会生成错误
- kubernetes - Kubernetes autoscaler:在特定日期更改最小副本