2

Am I missing something? This MDN example looked quite useful at first glance:

article[data-columns='3'] {
  width: 400px;
}
article[data-columns='4'] {
  width: 600px;
}

But this is little different to using

article[myAttr='3']{..., or article.cols3{...

either of which can be manipulated fairly easily with javascript/jQuery.

What would be very powerful is:

article[data-fieldwidth]{
 width: data-fieldwidth;
}   

but this isn't described anywhere and doesn't work in any of my tests. Is that correct?

1
  • 2
    this width: data-fieldwidth; does't work (in css) Commented May 12, 2016 at 17:49

1 Answer 1

2

If you want to get the value of an attribute you should use the CSS attr function. Currently the value of the property is not valuated and it's set as it is.

article[data-fieldwidth] {
 width: attr(data-fieldwidth);
} 

But note that:

The attr() function can be used with any CSS property, but support for properties other than content(property) is experimental.

Sign up to request clarification or add additional context in comments.

2 Comments

yikes, currently no browser support other than content, nice catch
@BenSewards Unfortunately. I'm sure implementing this feature in browsers can be very tricky.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.