EN
CSS - style first element only
0
points
In this article, we would like to show you how to style the first element only using CSS.
Quick solution:
element:first-child {
/* style properties here */
}
Practical example
In this example, we create a style for the first div element only using :first-child.
// ONLINE-RUNNER:browser;
<!doctype html>
<html>
<head>
<style>
div:first-child {
background: yellow;
}
</style>
</head>
<body>
<div>div 1</div>
<div>div 2</div>
<div>div 3</div>
</body>
</html>