4

This is my Html. I gave data-views as 190.

<ul>
   <li class="lecture" data-views="190"></li>
</ul>

This is my CSS Code. I am trying to get data-attribute value dynamically. How can I get this value of data-views as width .

$aaa:attr(data-views);
ul li:before{
  content:$aaa;
}
[data-views='$aaa']{
font-size:40px;
}
ul li{
  width : $aaa;
}
3
  • What do you mean by "get data-attribute value dynamically"? Commented Nov 18, 2015 at 6:17
  • thats scss not sass...sass has no bracket Commented Nov 18, 2015 at 6:28
  • You can do like: jsfiddle.net/wp7Wc/1012 Commented Nov 18, 2015 at 6:37

1 Answer 1

7

Your SCSS produces the following CSS:

ul li:before {
  content: attr(data-views);
}

[data-views='$aaa'] {
  font-size: 40px;
}

ul li {
  width: attr(data-views);
}

That is perfectly valid CSS, but has 2 problems:

  1. [data-views='$aaa'] is probably not what you wanted, [data-views] makes more sense. This will select (have effect on..) elements that have the data-views attribute.
  2. width: attr(data-views) is legal, but unsupported by any browser at the moment. Unfortunately, there's nothing you can do about it.

As SASS (like all other preprocessed CSS flavors) produces standard CSS, you can only do whatever CSS allows you to. You can't have the preprocessor "compute" CSS rules out of non existing (at compile time) markup.

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

Comments

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.