Home > Web Front-end > HTML Tutorial > 【CSS3】-last-of-type selector nth-last-of-type(n) selector_html/css_WEB-ITnose

【CSS3】-last-of-type selector nth-last-of-type(n) selector_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:45:44
Original
1216 people have browsed it

last-of-type selector

":last-of-type" selector and ":first-of-type" selector functionality It's the same, the difference is that it selects the last child element of a certain type under the parent element.

Example demonstration

Set the background of the last paragraph element in the container "div.wrapper" to orange through the ":last-of-type" selector

( Tip: This paragraph is not the last child element of the "div.wrapper" container).

HTML code:

<div class="wrapper">  <p>我是第一个段落</p>  <p>我是第二个段落</p>  <p>我是第三个段落</p>  <div>我是第一个Div元素</div>  <div>我是第二个Div元素</div>  <div>我是第三个Div元素</div></div>
Copy after login

CSS code:

.wrapper > p:last-of-type{  background: orange;}
Copy after login

Demo results:

nth-last-of-type(n) selector

":nth-last-of The -type(n)" selector is the same as the ":nth-of-type(n)" selector. It selects a certain child element type specified in the parent element, but its starting direction is from the last child element. , and its usage is similar to the ":nth-last-child(n)" selector introduced in the previous section.

Example demonstration

Wrap the third-to-last paragraph in the container "div.wrapper" through the ":nth-last-of-type(n)" selector The background is set to orange.

HTML code:

<div class="wrapper">  <p>我是第一个段落</p>  <p>我是第二个段落</p>  <p>我是第三个段落</p>  <p>我是第四个段落</p>  <p>我是第五个段落</p>  <div>我是一个Div元素</div>  <p>我是第六个段落</p>  <p>我是第七个段落</p></div>
Copy after login

CSS code:

.wrapper > p:nth-last-of-type(3){  background: orange;}
Copy after login

Demo results:

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template