用一个css还是两个,在一个元素上使用两个CSS类

I know this post is getting outdated, but here's what they asked.

In your style sheet:

.social {

width: 330px;

height: 75px;

float: right;

text-align: left;

padding: 10px 0;

border-bottom: dotted 1px #6d6d6d;

}

[class~="first"] {

padding-top:0;

}

[class~="last"] {

border:0;

}

But it may be a bad way to use selectors. Also, if you need multiple "first" extension, you'll have to be sure to set different name, or to refine your selector.

[class="social first"] {...}

I hope this will help someone, it can be pretty handy in some situation.

For exemple, if you have a tiny piece of css that has to be linked to many different components, and you don't want to write a hundred time the same code.

div.myClass1 {font-weight:bold;}

div.myClass2 {font-style:italic;}

...

div.myClassN {text-shadow:silver 1px 1px 1px;}

div.myClass1.red {color:red;}

div.myClass2.red {color:red;}

...

div.myClassN.red {color:red;}

Becomes:

div.myClass1 {font-weight:bold;}

div.myClass2 {font-style:italic;}

...

div.myClassN {text-shadow:silver 1px 1px 1px;}

[class~=red] {color:red;}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值