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

Discussion in 'ASP .Net' started by Cal Who, May 16, 2010.

  1. Cal Who

    Cal Who Guest

    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
     
    Cal Who, May 16, 2010
    #1
    1. Advertisements

  2. On May 16, 10:05 pm, " Cal Who" <> wrote:
    > 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...
     
    Alexey Smirnov, May 16, 2010
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nehmo Sergheyev
    Replies:
    1
    Views:
    678
    Andrew Urquhart
    May 9, 2004
  2. Marcin Vorbrodt

    ::std sometimes needed, sometimes not

    Marcin Vorbrodt, Sep 16, 2003, in forum: C++
    Replies:
    24
    Views:
    1,058
    Jerry Coffin
    Sep 17, 2003
  3. Replies:
    1
    Views:
    640
    gkelly
    Nov 29, 2006
  4. =?Utf-8?B?QmlzaG95?=
    Replies:
    0
    Views:
    1,259
    =?Utf-8?B?QmlzaG95?=
    Dec 28, 2006
  5. Randy Smith
    Replies:
    2
    Views:
    636
    Randy Smith
    Apr 24, 2007
  6. Stef Mientki
    Replies:
    0
    Views:
    307
    Stef Mientki
    Oct 18, 2008
  7. Cal Who
    Replies:
    4
    Views:
    766
    Cal Who
    May 17, 2010
  8. Oran
    Replies:
    2
    Views:
    808
Loading...