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

  • Thread starter Thread starter Cal Who
  • Start date Start date
C

Cal Who

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
 
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

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...
 
Back
Top