Comments on: Adjacent sibling https://css-tricks.com Tips, Tricks, and Techniques on using Cascading Style Sheets. Wed, 02 May 2018 15:49:26 +0000 hourly 1 https://wordpress.org/?v=6.1.1 By: Dinko Skopljak | Futura Web https://css-tricks.com/almanac/selectors/a/adjacent-sibling/#comment-1631975 Wed, 02 May 2018 15:49:26 +0000 http://css-tricks.com/?page_id=14150#comment-1631975 In reply to Peter Müller.

servus peter, here is a real example for this: if i have 100 divs, and i want to pick just the very next element of each .something-class. btw, contao rules! ;-)

]]>
By: Tim Malone https://css-tricks.com/almanac/selectors/a/adjacent-sibling/#comment-1618060 Sat, 24 Mar 2018 04:38:19 +0000 http://css-tricks.com/?page_id=14150#comment-1618060 In reply to Peter Müller.

How about this:

h1, h2 { margin: 1em 0 }
h1 + h2 { margin-top: -.5em }

Margins for h1 and h2 headings, except for when an h2 appears directly after a h1 (real world use case: you might have section headings for a post, without having an introduction paragraph for the post, and it looks weird having that extra spacing).

]]>
By: Tia Wood https://css-tricks.com/almanac/selectors/a/adjacent-sibling/#comment-1613793 Thu, 14 Dec 2017 19:41:06 +0000 http://css-tricks.com/?page_id=14150#comment-1613793 @Rob Y

I know this is over a year ago but answering in case others read it.

I think it’s because .body-class p + .body-class img are technically not next adjacent to each other.

This would be correct:

.body-class p + img

You probably don’t have another .body-class directly adjacent to p so I don’t think it’s going to select correctly.

]]>
By: Avaroth https://css-tricks.com/almanac/selectors/a/adjacent-sibling/#comment-1604870 Mon, 07 Nov 2016 12:17:07 +0000 http://css-tricks.com/?page_id=14150#comment-1604870 In reply to surender sharma.

How about :nth-of-type instead of nth-child? His way you will only select the, for example 5th li element, no matter how many other elements are in this .container element.

]]>
By: Rob Y https://css-tricks.com/almanac/selectors/a/adjacent-sibling/#comment-1603211 Thu, 04 Aug 2016 05:41:56 +0000 http://css-tricks.com/?page_id=14150#comment-1603211 In reply to Rob Y.

TK, I think this will target a span child of a div sibling to .body-class p:

.body-class p + div span {
    property: value;
}
]]>
By: Rob Y https://css-tricks.com/almanac/selectors/a/adjacent-sibling/#comment-1603209 Thu, 04 Aug 2016 05:39:01 +0000 http://css-tricks.com/?page_id=14150#comment-1603209 In reply to Rob Y.

Hey WilliC,

That was a typo, but it still doesn’t work. I think it’s looking for a direct sibling, so the following does not work:

.body-class p + .body-class img {
    property: value
}

but the following does:

.body-class p + img {
    property: value
}
]]>
By: WilliC https://css-tricks.com/almanac/selectors/a/adjacent-sibling/#comment-1603126 Fri, 29 Jul 2016 17:32:09 +0000 http://css-tricks.com/?page_id=14150#comment-1603126 In reply to Rob Y.

Is it not working because you are selecting the class .p instead of the element p?

.body-class p + .body-class img {
   color: white;
}
]]>
By: TK https://css-tricks.com/almanac/selectors/a/adjacent-sibling/#comment-1603112 Thu, 28 Jul 2016 08:40:57 +0000 http://css-tricks.com/?page_id=14150#comment-1603112 In reply to Rob Y.

I’ve got the same problem.

I would like to style the child element of a sibling.
Have you found an answer yet?

]]>
By: Rob Y https://css-tricks.com/almanac/selectors/a/adjacent-sibling/#comment-1600526 Fri, 25 Mar 2016 04:10:33 +0000 http://css-tricks.com/?page_id=14150#comment-1600526 I noticed that the following does not work. Any thoughts or workarounds?

.body-class .p + .body-class img {
   color: white;
}
]]>
By: surender sharma https://css-tricks.com/almanac/selectors/a/adjacent-sibling/#comment-1600153 Thu, 10 Mar 2016 12:39:07 +0000 http://css-tricks.com/?page_id=14150#comment-1600153

]]>
By: surender sharma https://css-tricks.com/almanac/selectors/a/adjacent-sibling/#comment-1600152 Thu, 10 Mar 2016 12:35:11 +0000 http://css-tricks.com/?page_id=14150#comment-1600152 is there any shortcut method to avoid so many + sign if i want to style 10th element with adjacent-sibling ? i don’t want to use nth-child
for ex:- .container > li + li + li + li + li{}

]]>
By: Mark https://css-tricks.com/almanac/selectors/a/adjacent-sibling/#comment-1599911 Sun, 28 Feb 2016 14:26:16 +0000 http://css-tricks.com/?page_id=14150#comment-1599911 This is a nice concise description. Thanks.

]]>
By: Peter Müller https://css-tricks.com/almanac/selectors/a/adjacent-sibling/#comment-1597960 Thu, 12 Nov 2015 09:40:19 +0000 http://css-tricks.com/?page_id=14150#comment-1597960 The explanation is clear, but I find it hard to come up with good every-day examples for using the + combinator in real-life CSS ;-)

The above example illustrates its point, but for captions I would use a figure-element surrounding the img and a figcaption-element:

<figure>
  <img src="..." alt=" "> 
  <figcaption>caption for image</figcaption> 
</figure>

That way you can easily style the caption without an adjacent sibling selector. Does any one have real-world examples für the adjacent + combinator?

]]>
By: McLeod https://css-tricks.com/almanac/selectors/a/adjacent-sibling/#comment-1597234 Sat, 26 Sep 2015 21:38:06 +0000 http://css-tricks.com/?page_id=14150#comment-1597234 The clearest definition of this I’ve found. Thanks!

]]>
By: Jam https://css-tricks.com/almanac/selectors/a/adjacent-sibling/#comment-1594908 Tue, 26 May 2015 18:38:28 +0000 http://css-tricks.com/?page_id=14150#comment-1594908 Thanks folks!

]]>