Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to have margin-left: 10%; margin-right: 10%;" only sometimes

4 views
Skip to first unread message

Cal Who

unread,
May 16, 2010, 4:05:00 PM5/16/10
to
Hi,

My website is created so that the width is not fixed. I adapt to the width
of the browser. If I have a page of text I do something like:

<div style=" margin-left: 10%; margin-right: 10%;">

so the text is set off by margins.

That's nice on my monitor's 1600 pixel wide screen.

But on a laptop (or as a user option) I'd like to change that to no margins.

Can you suggest a way of doing that without having two .css files?

Thanks


Alexey Smirnov

unread,
May 16, 2010, 4:53:48 PM5/16/10
to

For IE you can try to use CSS expressions, but I would recommend to
make a javascript to check screen width and set div style from there

e.g.

var x;
if (self.innerWidth) // all except Explorer
x = self.innerWidth;
else if (document.documentElement &&
document.documentElement.clientWidth)
// Explorer 6 Strict Mode
x = document.documentElement.clientWidth;
else if (document.body) // other Explorers
x = document.body.clientWidth;

if (x<1600)
... your code here...

0 new messages