...

View Full Version : Can we do calculations in CSS?



mOrloff
05-20-2009, 07:56 PM
For example, if I wanted to set width: (6em-11px); this obviously doesn't work, but does anyone have a trick that acheives this (w/out JS)?

~ Mo

_Aerospace_Eng_
05-20-2009, 08:06 PM
You will probably need to use xslt along with an xslt stylesheet. Its not an easy concept to grasp. It takes time. What exactly are you trying to do?

drhowarddrfine
05-20-2009, 10:50 PM
And CSS is not a programming language so such calculations are not possible.

mOrloff
05-21-2009, 02:08 AM
Thanks for both replies.

What I am trying to do is set flexible div width according to its sibling with a fixed width.
IE (example only):
<div id="wrapper" style="width:50em;">
<div id="right" style="width:25px;"></div>
<div id="left" style="width: (50em-25px);"></div>
</div>

~ Mo

_Aerospace_Eng_
05-21-2009, 02:40 AM
In that case just float the right div to the right and add a right margin on the left div.

<div id="wrapper" style="width:50em;">
<div id="right" style="width:25px;float:right;"></div>
<div id="left" style="margin-right:25px"></div>
</div>
You will need to overcome the IE 6 3px bug although if there is no background image in "left" then you won't need to worry about it.

http://www.positioniseverything.net/explorer/threepxtest.html

mOrloff
05-21-2009, 05:17 PM
Yeah, but that would be a logical solution, and who wants to deal with that?:p

Na, really. Thanks-a-bunch.

~ Mo

sivareddy
05-30-2013, 02:16 PM
For example, if I wanted to set width: (6em-11px); this obviously doesn't work, but does anyone have a trick that acheives this (w/out JS)?

~ Mo

Simply use,

width: calc(6em - 11px);

It works..!!

VIPStephan
05-30-2013, 04:41 PM
But be aware thatů



This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for the proper prefixes to use in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the spec changes.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum