Home >Web Front-end >HTML Tutorial >About CSS3:nth-child() selector_html/css_WEB-ITnose

About CSS3:nth-child() selector_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:57:241000browse

A page with many small squares. The class of the big square is big and the class of the small square is small. Use the css3 selector to write this:

.small:nth-child(even){margin-right:0;}


Set the even-numbered small The margin-right of the square is 0, but the margin-right of the third small square is equal to 0. What's going on?

demo: http://guusoft.com/test/


Reply to discussion (solution)

Through the guidance of other netizens , understand that selecting the odd-numbered or even-numbered child element from the parent element does not specify a certain type (.small), but all child elements are counted.
So the final solution is:

$(".small:odd").addClass("last");

Statement:
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