动态类可以使用CSS样式吗?

编程入门 行业动态 更新时间:2024-10-26 01:18:24
本文介绍了动态类可以使用CSS样式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个名为 .box-159 的类,其中每次刷新屏幕时数字都会改变。有没有办法定义这个字段(例如 background-color )在CSS?

解决方案

是,只需使用 CSS 即可。

选项#1 -
  • 使用 CSS ^ =class / strong>

=box-] {background:red; height:100px; width:100px; margin:10px 0; display:block}

< div class = 159>< / div>< span class =box-147>< / span>< article class =box-76878>< / article>

选项#2 - 匹配项至少包含一个值
  • 使用另一个 CSS类选择器 * =class(等效于 CSS属性选择器)选择所有其类包含至少一个子串 strong> box - 。

[class * =box-] {background:red; height:100px; width:100px; margin:10px 0; display:block}

< div class = 159>< / div>< span class =box-147>< / span>< article class =box-76878>< / article>

对于未来的读者,您可以在StackOverflow文档中找到关于此主题的更多信息此处

I have a class called .box-159 where the number changes every time the screen is refreshed. Is there a way to define this field (say background-color) in the CSS?

解决方案

Yes it is possible just by using CSS only.

Option #1 - Match by prefix value
  • Use CSS Class selector ^="class" which select all elements whose class is prefixed by "box-"

[class^="box-"] { background: red; height: 100px; width: 100px; margin: 10px 0; display:block }

<div class="box-159"></div> <span class="box-147"></span> <article class="box-76878"></article>

Option #2 - Match by contains at least one value
  • Use another CSS class selector *="class" (equivalent to CSS attribute selector) which select all elements whose class contains at least one substring "box-".

[class*="box-"] { background: red; height: 100px; width: 100px; margin: 10px 0; display:block }

<div class="box-159"></div> <span class="box-147"></span> <article class="box-76878"></article>

For future readers, you can find more information about this topic on StackOverflow Documentation here

更多推荐

动态类可以使用CSS样式吗?

本文发布于:2023-11-06 14:40:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563972.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以使用   样式   动态   CSS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!