adsense

Wednesday, February 27, 2019

CSS Accessing Elements using data attributes

When selecting elements in CSS, normally we user ID or class to select them. We can use data attribute in an element to select an element as shown below.

HTML

<div data-somename>
  Hi
</div>

CSS
[data-somename] {
color: red;
font-style: underline;

}

Cheers,
Samitha

No comments:

Post a Comment