tr:nth-child(2n+1) /* represents every odd row of an HTML table */ tr:nth-child(odd) /* same */ tr:nth-child(2n+0) /* represents every even row of an HTML table */ tr:nth-child(even) /* same */
:nth-child(10n-1)/* represents the 9th, 19th, 29th, etc, element */ :nth-child(10n+9)/* Same */ :nth-child(10n+-1)/* Syntactically invalid, and would be ignored */
当a=0,则an部分可以不包含。当an未包含且b为非负数,则在b前面的+字符也可省略。
实例:
1 2 3
foo:nth-child(0n+5) /* represents an element foo that is the 5th child of its parent element */ foo:nth-child(5) /* same */
当a=1或a=-1,数字可以从规则中省略。
实例:
1 2 3 4
bar:nth-child(1n+0) /* represents all bar elements, specificity (0,1,1) */ bar:nth-child(n+0) /* same */ bar:nth-child(n) /* same */ bar /* same but lower specificity (0,0,1) */
当b=0,则每一个第a个元素被选择。在这种情况,+b或-b部分可能省略,除非a部分已经被省略。
实例:
1 2
tr:nth-child(2n+0) /* represents every even row of an HTML table */ tr:nth-child(2n) /* same */
<P>This is a somewhat long HTML paragraph that will be broken into several lines. The first line will be identified by a fictional tag sequence. The other lines will be treated as ordinary lines in the paragraph.</P>
其中折行如下所示:
1 2 3 4 5
THIS IS A SOMEWHAT LONG HTML PARAGRAPH THAT will be broken into several lines. The first line will be identified by a fictional tag sequence. The other lines will be treated as ordinary lines in the paragraph.
<P><P::first-line> This is a somewhat long HTML paragraph that </P::first-line> will be broken into several lines. The first line will be identified by a fictional tag sequence. The other lines will be treated as ordinary lines in the paragraph.</P>
<P><SPANclass="test"> This is a somewhat long HTML paragraph that will be broken into several lines.</SPAN> The first line will be identified by a fictional tag sequence. The other lines will be treated as ordinary lines in the paragraph.</P>
用户代理会像下面这样处理:
1 2 3 4 5 6 7 8
<P><P::first-line><SPANclass="test"> This is a somewhat long HTML paragraph that will </SPAN></P::first-line><SPANclass="test"> be broken into several lines.</SPAN> The first line will be identified by a fictional tag sequence. The other lines will be treated as ordinary lines in the paragraph.</P>
取值:[ left | center | right | top | bottom | <percentage> | <length> ]
|
[ left | center | right | <percentage> | <length> ]
[ top | center | bottom | <percentage> | <length> ] <length>?
|
[ center | [ left | right ] ] && [ center | [ top | bottom ] ] <length>?
取值:[ left | center | right | top | bottom | <percentage> | <length> ]
|
[ left | center | right | <percentage> | <length> ]
[ top | center | bottom | <percentage> | <length> ] <length>?
|
[ center | [ left | right ] ] && [ center | [ top | bottom ] ] <length>?
<style> @media (min-width: 60em) { /* two column layout only when enough room (relative to default text size) */ header + div{ display: flex; } #main{ flex:1; /* Main takes up all remaining space */ order:1; /* Place it after (to the right of) the navigation */ min-width:12em; /* Optimize main content area sizing */ } } /* menu items use flex layout so that visibility:collapse will work */ nav > ul > li{ display: flex; flex-flow: column; } /* dynamically collapse submenus when not targetted */ nav > ul > li:not(:target):not(:hover) > ul { visibility: collapse; } </style> … </header> <div> <articleid="main"> Interesting Stuff to Read </article> <nav> <ul> <liid="nav-about"><ahref="#nav-about">About</a> … <liid="nav-projects"><ahref="#nav-projects">Projects</a> <ul> <li><ahref="…">Art</a> <li><ahref="…">Architecture</a> <li><ahref="…">Music</a> </ul> <liid="nav-interact"><ahref="#nav-interact">Interact</a> … </ul> </nav> </div>
.tabs{ display: flex; } .tabs > * { min-width: min-content; /* Prevent tabs from getting too small for their content. */ } .tabs > .current{ order: -1; /* Lower than the default of 0 */ }
@media all and (max-width: 600px) { /* Too narrow to support three columns */ #main{ flex-flow: column; } #main > article, #main > nav, #main > aside{ /* Return them to document order */ order:0; width: auto; } }
<style> nav > ul{ display: flex; } nav > ul > li{ min-width: min-content; /* Prevent items from getting too small for their content. */ } nav > ul > #login{ margin-left: auto; } </style> <nav> <ul> <li><ahref=/about>About</a> <li><ahref=/projects>Projects</a> <li><ahref=/interact>Interact</a> <liid='login'><ahref=/login>Login</a> </ul> </nav>
8.2 轴对齐:justify-content属性
名称:justify-content
取值:flex-start | flex-end | center | space-between | space-around