EN
CSS - use element id in style selector
0
points
In this article, we would like to show you how to use element id in style selector using CSS.
Quick solution:
#elemet-id {
/* style properties here */
}
Practical example
In this example, we create the style for elements with id = my-element, then we assign the style to the my-element inside body section using id property.
Note:
Styling using
idproperty isn't good because the identifiers should be unique for each element in the application.
// ONLINE-RUNNER:browser;
<!doctype html>
<html>
<head>
<style>
#my-element {
background: yellow;
}
</style>
</head>
<body>
<div id="my-element">Example text.</div>
</body>
</html>