# How to calculate the width for a = current browser window width MINUS 180 pixel?

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on

I would like to dynamically calculate the width of a <div> pane as
the current browser window width minus 180 pixel.

In other words I would like to setup an CSS instruction like

DIV.special { width: calculate(100% - 180px); }

Unfortuantely this does not work.

How else can I achieve this with HTML/CSS ?

Chris

## Re: How to calculate the width for a = current browser window width MINUS 180 pixel?

chrpearl@hotmail.com (Chris Pearl) wrote:

If you just want it 180px narrower, set margin-left and
margin-right to a total of 180px.

If you need more than that, it might help to provide
more detail...

## Re: How to calculate the width for a = current browser window width MINUS 180 pixel?

On 1/25/2010 9:16 AM, David Stone wrote:

Actually, each margin should be half of the total reduction.  That is,
90px for each of margin-left and margin-right.  Even with that
correction, however, you will lose about half the available window width
for the content of the DIV if the browser window is "normalized"
(neither maximized nor minimized) to a width of half the screen on a
800x600 monitor.

--

David E. Ross
<http://www.rossde.com/ .

"Why NOT Road Rage?" or "Why Is There No Such
Thing as Fast Enough?"

## Re: How to calculate the width for a = current browser window width MINUS 180 pixel?

On 2010-01-25 14:23, David E. Ross wrote:

Not necessarily.  David Stone was correct in saying that the *total*
should be 180px:  he made no assumption as to whether the OP wanted his
DIV centred.

Though, of course, the OP should consider the size of the padding,
border, and margin, as this can affect the sizes of the margins.

## Re: How to calculate the width for a = current browser window width MINUS 180 pixel?

On 1/25/2010 8:45 AM, Chris Pearl wrote:

You need a script for this, and even that might not give you what you
want.  The sticking point is the absolute 180px, which will give you
different results depending on the overall monitor size and screen
resolution.  For example, 180px is a much narrower strip on the screen
for 1280x1024 resolution than for 800x600.  On top of that, 180px might
be an excessive width of a browser window that is not maximized on the
screen.

I suggest that you determine what percentage of your own screen is 180px
and set the width to 100% minus that percentage.  That is, if you have
1280x1024 resolution, 180px is 14% of the width of your screen.  100%
minus 14% is 86%.  Just use
DIV.special { width: 86% }
This will provide a style that adapts to varying monitor sizes, screen
resolutions, and browser window configurations.

--

David E. Ross
<http://www.rossde.com/ .

"Why NOT Road Rage?" or "Why Is There No Such
Thing as Fast Enough?"

## Re: How to calculate the width for a = current browser window width MINUS 180 pixel?

In article
chrpearl@hotmail.com (Chris Pearl) wrote:

http://dorayme.netweaver.com.au/alt/div180Less.html

--
dorayme

## Re: How to calculate the width for a = current browser window width MINUS 180 pixel?

On 25 Jan 2010, chrpearl@hotmail.com (Chris Pearl)  wrote:

Not, at least, in the way you indicate.  Would require javascript for
calculation.

--
Neredbojias
http://www.neredbojias.org /
http://www.neredbojias.net /

## Re: How to calculate the width for a = current browser window width MINUS 180 pixel?

Chris Pearl wrote:

Cannot with HTML or CSS requires JavaScript.

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com