html - 如何使样式颜色全局化?

标签 html css

我确定这个问题在某个地方得到了回答,但我找不到,我什至不确定如何正确描述这个问题

我正在寻找某种方式将颜色代码部分放入 css 中,这样它就变成了全局的,这样我就可以更改所有可以一次更改的实例。

否则很难看到透明链接..

<a href="#" style="color: rgb(255,0,0,0)" onclick="playclip(); return false;" >xxxxxxxxxxxxx </a> </span></p>

也许是通过类解决的?

类似于:

<a href="#" style=.color1 onclick="playclip(); return false;" >xxxxxxxxxxxxx
My personal knowledge about css is, maybe, 1%..

最佳答案

.myClass {
  color: rgb(255,0,0);
}
<a href="#" class="myClass" onclick="playclip(); return false;" >xx</a>
<a href="#" onclick="playclip(); return false;" >xxx</a>
<a href="#" onclick="playclip(); return false;" >xxxxx</a>
<a href="#" class="myClass" onclick="playclip(); return false;" >xxxxxx</a>
<a href="#" class="myClass" onclick="playclip(); return false;" >xxxx</a>

使用具有已定义样式的 class 并将该类名称赋予您要定位的元素(本例中为 class="myClass")。像这样:

HTML

<a href="#" class="myClass" onclick="playclip(); return false;" >xx</a>
<a href="#" onclick="playclip(); return false;" >xxx</a>
<a href="#" onclick="playclip(); return false;" >xxxxx</a>
<a href="#" class="myClass" onclick="playclip(); return false;" >xxxxxx</a>
<a href="#" class="myClass" onclick="playclip(); return false;" >xxxx</a>

在你的 CSS 文件中定义你使用的类

CSS

.myClass {
  color: rgb(255,0,0); // change only this to affect all with this class name
}

Note: Ideally rgb should have only 3 parameters representing red, green, blue(255, 0, 0) respectively and rgba should have 4 parameters representing red, green, blue, alpha(255, 0, 0, 0.5). The last parameter alpha represents transparency. You can use any of your choice.

在您的问题中,您提到了color: rgb(255,0,0,0)。这是不正确的,因为您使用的是带有 4 个参数(不是 3 个)的 rgb 函数。这不会为您提供所需的 red 颜色。 color: rgb(255, 0, 0) 是正确的。

关于html - 如何使样式颜色全局化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44549860/

相关文章:

javascript - 仅在一个地方编写菜单栏

javascript - 根据 jquery 中的条件将 div 保留在另一个 div 的末尾

css - 在调整大小时删除某些列表元素(桌面到移动 View )

使用变量的 jQuery CSS 悬停

html - 如何使用静态字符串为分层有序列表项编号添加前缀

python - 从 BeautifulSoup Python中提取链接标题

html - Symfony3 中的未知 "stylesheets"标签

html - :focus must be clicked twice 上的另一个案例

css - 如何将 css 应用于 Internet Explorer 中文本字段的特定标签

图像上的 Firefox 中的 CSS3 动画不透明度