First / Last child for margin not working?
See original GitHub issueI’ve been playing around with pseudo class, but it’s seems margin won’t be affected by pseudo class?
e.g
# working
first:border
# not working
first:mx-0
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
First / Last child for margin not working in the Next.js ...
you could try using the space-y utitlity class.
Read more >last-child - CSS: Cascading Style Sheets - MDN Web Docs
The :last-child CSS pseudo-class represents the last element among a group of sibling elements.
Read more >Everything You Need To Know About CSS Margins
See the Pen Margins: margin on first and last child doesn't collapse if the parent has a border by Rachel Andrew. Once again,...
Read more >Remove Margins for First/Last Elements - CSS-Tricks
It can sometimes be desirable to remove the top or left margin from the first element in a container. Likewise, the right or...
Read more >CSS | :not(:last-child):after Selector - GeeksforGeeks
:after This is a great selector to add content (or sometimes, even block-level elements) after the selected elements (Here the first inner-div ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You want to select the direct children with the
>
combinator in addition to using the:nth-child
psuedo class. The nth-child psuedo class doesn’t automatically point at the children but rather asks if the currently selected object is the nth child. Perhaps a bit confusing as the word “child” is part of the psuedo class 😛 So. In your case you need to put& > :nth-child(3)
inside the square brackets. Like so:this will first target all direct children of the div tag with the
>
and then match the one which is the 3rd childplayground link: https://play.tailwindcss.com/1tRLpoO1zC
Additional Update: also be aware that if you want to use the last-child psuedo class, the name is actually
:last-child
. Notlast
, which is tailwind’s short utility name for it.[&>:last-child]:text-blue-400
https://play.tailwindcss.com/9pGwUY7QKe@robbyrice I am trying to use these two selector first and last but not working , could you please help me ? Tailwind Playground link