开发者

CSS optimization in terms of LoC

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜