3

I have some css class like this:

.ft-*{
    font-size: .*px;
}

Is there anyway to define css whenever I call something like <div class="ft-16">hello</div> some property like font size changes to 16? I mean can css input something instead of * mark like number,..?

4 Answers 4

6

No. CSS does not support this. Use a CSS preprocessor language such as LESS or SASS for this sort of feature.

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

1 Comment

Indeed. Using the loop functionality of LESS this can be done easily enough: blog.thehippo.de/2012/04/programming/do-a-loop-with-less-css
1

For something like this you could need to use a css preprocesser and Mixins.

Comments

1

You could use JS to find and define them, but you are probably better off simply taking the time to define the classes you will need and then they are there for when you need them throughout the project. It probably won't payoff in terms of time in/benefit out.

Just set up a bunch of classes:

.ft-12 {}
.ft-14 {}
.ft-16 {}

etc etc

It's worth it to keep things simple.

Comments

0

I would suggest a jQuery aproach:

var font_size = temp_css_class.split('-')[1];

$( temp_css_class ).each(function() {
  $(this).css("font-size", font_size + "px");
});

Where "temp_css_class" is your class name.

3 Comments

This is a pretty "dumb" approach. It will be significantly slower than CSS, clutters JavaScript with CSS concerns, and does not apply to elements added to the page after the snippet runs.
Still the only way to do it without LESS or SASS?
I'd argue that @TimPalmer's way is better, sans LESS/SASS.

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.