Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we specify custom data attribute values in CSS?

On elements I can specify the data attributes as, e.g.

<div data-widget-type="MyWidgetType1" data-property1="20" data-property2="test">
...
</div>

I want to capture these in a class e.g.

.MyClass1 {
 data-widget-type:"MyWidgetType1";
 data-property1:"20";
 data-property2:"test";
}

<div class="MyClass1">
...
</div>

Is there a way to specify data attribute values in CSS?

like image 441
Nitesh Avatar asked Apr 12 '16 06:04

Nitesh


1 Answers

No, there is no such functionality even for default attributes (like you can't set name attribute via CSS). But you can select these custom attributes:

.MyClass1[data-widget-type="MyWidgetType1"]
like image 144
Justinas Avatar answered Oct 28 '22 01:10

Justinas