CSS Mastery摘要(1)--Getting Your Styles to Hit the Target

we’ve used the ::first-letterpseudo-element to create a drop-cap letter in a different font at the beginning of the paragraph.

 

.comment:target:not(.comment-downvoted) {
     background-color: #fffec4;
}


tr:nth-child(3n+4) {
   background: #ddd;
}

Back in CSS 2.1 there was a pseudo-element for the first child, sensibly named:first-child, so:nthchild(1)can be written more simply using that. The Level 3 selectors specification adds a corresponding one for the last child, named (you guessed it) :last-child, corresponding to:nth-last-child(1). There’s also :only-childand:only-of-type. The:only-of-typeselector applies to an element if it is the only child element that is of a particular element type. We can get more advanced with targeting elements of a certain type by using these pseudo-class selectors:
:nth-of-type(N)
:nth-last-of-type(N)


Form Pseudo-Classes

/* When the field contains a valid email address: */
input[type="email"]:valid {
  border-color: green;
}
/* When the contents are not a valid email address: */
input[type="email"]:invalid {
  border-color: red;
}

People often confuse inheritance with the cascade. Although they seem related at first glance, the two concepts are actually quite different.

Inherited property values have no specificity at all, not even zero. This means that properties set via the universal selector, which has a specificity of zero, will override inherited properties.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值