Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is Math in Style attribute posible?

Status
Not open for further replies.

Solojer

Technical User
Feb 28, 2008
54
CA
I've written a script that will auto generate CSS for a page I'm making. For the script, it would be much easier if I were able to use some math in the attribute rather than calculating it before the code is generated. I tested it out, and it does not seem to work. I was hoping if someone here could let me know if I have a problem with my syntax, or if it really isn't possible.


CSS:
style ="height:2px*5px;"

Thanks in advance!!
 
Hi

Do not try to guess the syntax. Read the specification instead : CSS3 | Functional Notations | Mathematical Expressions: ‘calc()’.

According to When can I use... calc() as CSS unit value is not supported by Opera and the mobile browsers.

Regarding the expression you posted, [tt]calc()[/tt] is an overkill for that. A CSS framework would be enough for such static[sup](*)[/sup] calculation.
[small](*) I mean, no dynamic value involved, it not depends on rendering.[/small]

Feherke.
[link feherke.github.com/][/url]
 
Thanks for your help with this feherke.. I'm a bit in the dark when it comes to many things CSS related, would you mind being a bit more specific when you mention a CSS framework?

Also, unfortunately, my audience is using primarily IE8, so the calc function doesn't look like it will work based on the link you sent me...
 
Hi

Solojer said:
would you mind being a bit more specific when you mention a CSS framework?
They are kind of preprocessors to expand some additional syntax elements. They transform a source code containing mostly CSS elements mixed with macros into regular CSS code.

Some of such frameworks ( maybe not the most correct expression, only xCSS calls itself CSS framework ) are LESS, Sass, xCSS, HSS, CleverCSS.

Note that CSS frameworks are useful for processing CSS files, not [tt]style[/tt] attributes. Also note that your site will be easier to maintain if you separate content and presentation. I mean, avoid using inline style.


Feherke.
[link feherke.github.com/][/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top