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

来源:互联网 发布:江苏国税普通发票软件 编辑:程序博客网 时间:2024/06/09 13:51

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.

原创粉丝点击