[Last Call] Learn how to a build a cloud-first strategyRegister Now


Subtract pixles from a percent?

Posted on 2005-05-12
Medium Priority
Last Modified: 2009-03-27
Call me crazy but i was looking for someing CSS related the other day and i stumbled across some more advanced things you could do..  now i can't find the page (i am sure i booked marked it but it must have been at work) any way this site said that it's possiable to define the width in somethign by a percent then subtract the amout of pixles from it example..

width: 100% - 10px;

can you really do this.. and if so how?
Question by:mightofnight
LVL 30

Assisted Solution

GrandSchtroumpf earned 1000 total points
ID: 13993072
That would be very nice...

But unfortunately AFAIK, it does not work.
It might be included in future CSS specs.

However, IE supports the "expression" in css, that allows you to use the results of a javascript function.  Like this:
  width: expression(300 - 200);

But I don't think you can use it to mix percentages with pixels.
LVL 53

Accepted Solution

COBOLdinosaur earned 1000 total points
ID: 13994879
Well yu can't directly in CSS by a little bit of script will do it.  No matter how the the element is styled, it still has a width and dight in pixels for he rendering engine.

so if you ahve something like:

<div id="the div" style="90%" onclick="makeNarrow(this,100)">

Then you just need to have this in  head o fthe page:

<script type="text/javascript">
function makeNarrow(el, factor)


Author Comment

ID: 14001226
ya i found the site that i was looking back it was the expressions and as said i had mixed results.  

Thanks forthe code Cd& i am not sure i only played around with it a little but it seams to work descent!

thanks for the input guys...

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When applying CSS to your HTML, there are many different ways to select which element(s) the CSS applies to.  Some of these selectors are more commonly known and used than others - Here are the more common ones: #X - Matches an ID of X .X - Matche…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
Suggested Courses
Course of the Month18 days, 2 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question