0

Is it possible create a custom class for example:

border {
  border:1px solid;
}

and apply directly in a tag, without need of class=""?

Example: <div class="row" border></div>

Daniel_Knights
  • 7,940
  • 4
  • 21
  • 49
Shinomoto Asakura
  • 1,473
  • 7
  • 25
  • 45

2 Answers2

3

Well, you can. But as @G-Cyrillus said in the comments to create a custom attribute in your HTML element it is better to use HTML data-attribute to stick with the HTML standards. Then you can style your element without adding a class attribute.

So if you don't want to add it as a data-attribute you can style it like this:

[border] {
  width: 100px;
  height: 100px;
  border: 1px solid;
}
<div class="row" border></div>

And with the data-attribute (Which is the standard one) you can do the same:

div[data-border] {
  width: 100px;
  height: 100px;
  border: 1px solid;
}
<div class="row" data-border></div>
SMAKSS
  • 9,606
  • 3
  • 19
  • 34
  • 1
    see my comment about the data-attribute made for this kind of use ;) to fullfill your answer. – G-Cyrillus Oct 19 '20 at 17:21
  • @G-Cyrillus That is exactly what I want to add. Thank you. I just searching for it. – SMAKSS Oct 19 '20 at 17:22
  • I agree with G-Cyrillus, you should probably use a data attribute, e.g.
    . Then in css you would just have [data-border] { width: 100px; height: 100px; border: 1px solid }. See here for details: https://css-tricks.com/a-complete-guide-to-data-attributes/
    – Michael Tucker Oct 19 '20 at 17:22
1

What you want can be accomplished by using a javascript framework like VueJs or React. I know, in VueJs it's called a prop that you pass to a child element. Whether or not the prop (border in your case) is passed down, the styling is applied or not.