This type of calculation is not currently supported in CSS (of course, not in Chromium 12 / Ubuntu 11.04), but there is a calc() function defined in CSS 3 that would allow this behavior using simple mathematical functions:
section { float: left; margin: 1em; border: solid 1px; width: calc(100%/3 - 2*1em - 2*1px); } p { margin: calc(1rem - 2px) calc(1rem - 1px); border: solid transparent; border-width: 2px 1px; } p:hover { border-color: yellow; }
(Example above, taken directly from W3.org .)
My own (exhaustive) tests show:
+----------------+-------------------+ | Browser | Ubuntu 11.04 | +----------------+-------------------+ | Chromium 12 | Fails | | Firefox 5 | Fails | | Opera 11.10 | Fails | +----------------+-------------------+
The above results were obtained using the above browsers and css calc() demo , the code of which is below:
HTML:
<div id="box">This is the box.</div>
CSS
#box { width: calc(100% - 20%); background-color: #f90; font-weight: bold; color: #fff; line-height: 2em; text-align: center; margin: auto; }
(If someone wants to run the above test in browsers on their platform and provide the results or edit them in this answer, it will be much appreciated.)
As stated, clairesuzy in the comments:
[Take a look at caniuse it works in Firefox if you use width: -moz-calc() but more on that;)
Indeed, it works in Firefox 5 (Ubuntu 11.04) (other vendor prefixes do nothing for Opera or Webkit, but unfortunately): Revised demo version with a vendor prefix .
Link:
David thomas
source share