html - CSS :first-child pseudo-element -
why code not working intended? background-color of first article must green. how can without classes or id? p.s. i'm sorry post needs more text. i'm sorry post needs more text.
<!doctype html> <html> <head> <meta charset="utf-8"> <title>stack</title> <link rel="stylesheet" href="css/style_new.css"> </head> <body> <section> <h1>this h1 header</h1> <article> <p> lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit </p> </article> <article> <p> lorem ipsum dolor sit amet, consectetur adipisicing elit, sed eiusmod tempor incididunt ut labore et dolore magna aliqua. ut enim ad minim veniam, </p> </article> <article> <p> lorem ipsum dolor sit amet, consectetur adipisicing elit, sed eiusmod tempor incididunt ut labore et dolore magna aliqua. ut enim ad minim veniam, </p> </article> </section> </body> </html>
css code:
section article:first-child { background-color: green; } section article:last-child { background-color: red; }
actually first child of section tag h1 not article. use below code instead,
section article:first-of-type { background-color: green; }
Comments
Post a Comment