use*_*451 11 html css css-selectors css3
我有一个类.box-159,在每次刷新屏幕时,数字都会改变.有没有办法background-color在CSS中定义这个字段(比如说)?
dip*_*pas 22
是的,只能使用CSS.
^="class"选择其类以" box- " 为前缀的所有元素[class^="box-"] {
background: red;
height: 100px;
width: 100px;
margin: 10px 0;
display:block
}Run Code Online (Sandbox Code Playgroud)
<div class="box-159"></div>
<span class="box-147"></span>
<article class="box-76878"></article>Run Code Online (Sandbox Code Playgroud)
*="class"(相当于CSS属性选择器),它选择其类包含至少一个子字符串" box- "的所有元素.[class*="box-"] {
background: red;
height: 100px;
width: 100px;
margin: 10px 0;
display:block
}Run Code Online (Sandbox Code Playgroud)
<div class="box-159"></div>
<span class="box-147"></span>
<article class="box-76878"></article>Run Code Online (Sandbox Code Playgroud)
您可以添加一个附加类,如下所示,然后这两个元素都将具有该类的 CSS 属性:
.box-class {
background-color: red;
width: 100px;
height: 100px;
margin-bottom: 20px;
}Run Code Online (Sandbox Code Playgroud)
<div class="box-class box-4"></div>
<div class="box-class box-159"></div>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8726 次 |
| 最近记录: |