Table of Contents
Reply to discussion (solution)
Home Web Front-end HTML Tutorial About CSS3:nth-child() selector_html/css_WEB-ITnose

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

Jun 24, 2016 am 11:57 AM
css3 nth-child Selector

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;}
Copy after login


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");
Copy after login

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the identifier of the id selector in css What is the identifier of the id selector in css Sep 22, 2022 pm 03:57 PM

What is the identifier of the id selector in css

How to implement lace borders in css3 How to implement lace borders in css3 Sep 16, 2022 pm 07:11 PM

How to implement lace borders in css3

Use the :nth-child(n+3) pseudo-class selector to select the style of child elements whose position is greater than or equal to 3 Use the :nth-child(n+3) pseudo-class selector to select the style of child elements whose position is greater than or equal to 3 Nov 20, 2023 am 11:20 AM

Use the :nth-child(n+3) pseudo-class selector to select the style of child elements whose position is greater than or equal to 3

Learn new CSS features: Directional clipping overflow:clip Learn new CSS features: Directional clipping overflow:clip Oct 11, 2022 pm 07:12 PM

Learn new CSS features: Directional clipping overflow:clip

From beginner to proficient: Master the skills of using is and where selectors From beginner to proficient: Master the skills of using is and where selectors Sep 08, 2023 am 09:15 AM

From beginner to proficient: Master the skills of using is and where selectors

What to do if the javascript selector fails What to do if the javascript selector fails Feb 10, 2023 am 10:15 AM

What to do if the javascript selector fails

What is nth-child? What is nth-child? Aug 04, 2023 am 11:00 AM

What is nth-child?

What are the wxss selectors? What are the wxss selectors? Sep 28, 2023 pm 04:27 PM

What are the wxss selectors?

See all articles