Home > Article > Web Front-end > How to specify that a style only applies to that element's parent element and that element's child elements in HTML?
Use the scoped attribute to specify that the style applies only to the parent element and its children -
<!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>
The above is the detailed content of How to specify that a style only applies to that element's parent element and that element's child elements in HTML?. For more information, please follow other related articles on the PHP Chinese website!