开发者

CSS optimization in terms of LoC

开发者 https://www.devze.com 2023-03-04 01:07 出处:网络
A silly question but just curious, say I have a css in the following format, .name1{color: b开发者_如何学Golack}

A silly question but just curious, say I have a css in the following format,

.name1{color: b开发者_如何学Golack}
.name2{color: red}
.name3{color: yellow}

Now I need to add some other property like text-decoration: underline on all this three. Instead of adding it in each rule as,

.name1{color: black,text-decoration: underline }
.name2{color: red,text-decoration: underline }
.name3{color: yellow,text-decoration: underline }

Is there a better way of doing it like clubbing them together for just the text-decoration: underline and use their color property as such. Something like inheritance or over-riding in OOPs.

Thanks, Abi


.name1,
.name2,
.name3 {
    text-decoration: underline;
}

You could also add a class to each element in the HTML and reference it once in the CSS.

Also, the property delimiter is ;, not ,.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号