Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sibling selectors in CSS3
#1
Example:

<!DOCTYPE html>
<html>
<head>
  <title>Sibling Selectors Example</title>
  <style>
    /* Select only the first sibling (immediate previous element) of h2 */
    h2 + p {
      font-style: italic;
    }
  </style>
</head>
<body>
  <h2>This is a heading</h2>
  <p>This paragraph will not be italic.</p>
  <p>This paragraph will be italic because it is the immediate sibling of h2.</p>
</body>
</html>

Explanation:

Sibling selectors (+) target elements that are immediate siblings of another element. In this example, the h2 + p selector selects the paragraph (<p>) that is the immediate sibling of the h2 element and applies italic font style to it.
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Child selectors in CSS3 Qomplainerz 0 249 07-26-2023, 07:16 PM
Last Post: Qomplainerz
  Attribute selectors in CSS3 Qomplainerz 0 278 07-26-2023, 07:12 PM
Last Post: Qomplainerz
  Selectors in CSS3 Qomplainerz 0 230 07-26-2023, 06:41 PM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 5 Guest(s)