tags:

views:

67

answers:

7

How to subtract width in CSS?

For example:

width = 100% - 10px

I'm not talking about padding or margin.

+1  A: 

this isn't possible - and was asked a thousand times before. please use the search before posting those questions.

oezi
sorry i didn't find
Jeaffrey Gilbert
+6  A: 

Simple: you can't do this. You'll have to use some workaround.

Peter
Yes after all i'm using margin. Thanks Peter.
Jeaffrey Gilbert
+1  A: 

Actually there is no such functionality. All you can do is:

width:auto;
margin-right: 10px;

what is not what you want.

Thariama
Yes after all i'm using margin. Thanks Thariama.
Jeaffrey Gilbert
+1  A: 

The only way to achieve this is to construct your CSS using LessCSS or a similar tool and then process these files into generated CSS - you can't do it on the fly

Nev Stokes
I try to use pure CSS, but thanks Nev.
Jeaffrey Gilbert
+4  A: 

Well, until CSS3 calc() is released in all major browsers, all you have to do is wrap one div with another and use some paddings-margins. OR, you can use some javascript, like counting the width of the screen and setting the width of a div accordingly.

n1313
Yes after all i'm using margin. Thanks n1313.
Jeaffrey Gilbert
+1  A: 

You might be able to do this with SASS, if you're using a stack which supports it. I'm only aware of Ruby, but there might well be others.

SASS is CSS-style code which generates traditional CSS, you can use variables and so on.

Grant Crofton
Nice reference, thanks Grant.
Jeaffrey Gilbert
+1  A: 

Usually, one uses a dynamic approach, that generates code on the fly. For instance, in PHP, while writing the CSS part,

 $width = $all - 10;
 echo 'width:' . $width . 'px;';
ring0
Yes we can do it with PHP, but I don't handle the server side part. Moreover, I have many elements which want to be applied. Thanks ring0.
Jeaffrey Gilbert