How to specify that the styles only apply to this element's parent element and that element's child elements in HTML?

HTMLWeb DevelopmentFront End Technology

Use the scoped attribute to specify that the styles only apply to the parent element and the element’s child elements −

Example

<!DOCTYPE html>
<html>
   <head>
      <style>
         h2 {
            color:yellow;
         }
      </style>
   </head>
   <body>
      <div>
         <style scoped>
            h2 {
               color:grey;
            }
         </style>
         <h2>Grey Heading</h2>
      </div>
      <h2>Yellow Heading</h2>
   </body>
</html>
raja
Published on 14-Mar-2018 10:31:37
Advertisements