padding-left, padding-right..

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • maya

    padding-left, padding-right..

    hi,

    I recently discovered the hard way that when you had padding-right or
    padding-left to a div it increases the with of the div... how do you
    add left-padding or right-padding to a div w/o changing the width of it?

    (for example: I have a div that's 320px wide, content inside is 300px
    and I added padding-left:10px but it increased with of div to 330px.. I
    want width of it to remain 320px but I need a padding on the left of 10px..)

    thank you..


  • Jeremy

    #2
    Re: padding-left, padding-right..

    maya wrote:
    hi,
    >
    I recently discovered the hard way that when you had padding-right or
    padding-left to a div it increases the with of the div... how do you
    add left-padding or right-padding to a div w/o changing the width of it?
    >
    (for example: I have a div that's 320px wide, content inside is 300px
    and I added padding-left:10px but it increased with of div to 330px.. I
    want width of it to remain 320px but I need a padding on the left of
    10px..)
    >
    thank you..
    >
    >
    I vaguely recall something from school - I think it was called
    "arithmetic " :-)

    <div style="width: 300px; padding: 10px"></div>

    300 + 2 * 10 = 320


    All kidding aside, if for some reason you can't just subtract the
    padding from the width of the box (i.e. if you're using different units
    for the width and the padding) then you can just add a second box inside
    the first, with no defined width and the padding you want:

    <div style="width: 60%">
    <div style="padding: 2em">
    <p>Content</p>
    </div>
    </div>


    Note: inline styles are for easy demonstration purposes. You shouldn't
    actually use them.

    Jeremy

    Comment

    • dorayme

      #3
      Re: padding-left, padding-right..

      In article <47f15341$1@new s.x-privat.org>, maya <maya778899@yah oo.com>
      wrote:
      hi,
      >
      I recently discovered the hard way that when you had padding-right or
      padding-left to a div it increases the with of the div... how do you
      add left-padding or right-padding to a div w/o changing the width of it?
      >
      (for example: I have a div that's 320px wide, content inside is 300px
      and I added padding-left:10px but it increased with of div to 330px.. I
      want width of it to remain 320px but I need a padding on the left of 10px..)
      >
      thank you..
      Would this example help you:

      <http://netweaver.com.a u/alt/widthPadding.ht ml>

      (the padding left is exaggerated to demonstrate. The url will not be for
      the world long.)

      --
      dorayme

      Comment

      • dorayme

        #4
        Re: padding-left, padding-right..

        In article <QsGdnb3BjIdHLm zanZ2dnUVZ_hqdn Z2d@earthlink.c om>,
        Jeff <jeff@spam_me_n ot.comwrote:
        dorayme wrote:
        In article <47f15341$1@new s.x-privat.org>, maya <maya778899@yah oo.com>
        wrote:
        hi,
        >
        I recently discovered the hard way that when you had padding-right or
        padding-left to a div it increases the with of the div... how do you
        add left-padding or right-padding to a div w/o changing the width of it?
        >
        (for example: I have a div that's 320px wide, content inside is 300px
        and I added padding-left:10px but it increased with of div to 330px.. I
        want width of it to remain 320px but I need a padding on the left of
        10px..)
        >
        thank you..
        Would this example help you:

        <http://netweaver.com.a u/alt/widthPadding.ht ml>

        (the padding left is exaggerated to demonstrate. The url will not be for
        the world long.)
        >
        >
        I think it's been a while since Dorayme wrote that, as she would not
        use a transitional doc-type now!
        Well, "she" (and much more correctly "it") should have been changed by
        me to Strict and it - no, not me! the other it, the html doc it - is now
        Strict. So thanks Jeff.

        I just grab whatever html file is lying around and throw something in it
        that is to some current need. On this occasion, I seemed to have grabbed
        something old or something used to discuss some difference between
        strict and not strict. <g>

        --
        dorayme

        Comment

        • dorayme

          #5
          Re: padding-left, padding-right..

          In article
          <doraymeRidTh is-95AA2C.15362801 042008@news-vip.optusnet.co m.au>,
          dorayme <doraymeRidThis @optusnet.com.a uwrote:
          Well, "she" (and much more correctly "it") should have been changed by
          me to Strict and it - no, not me! the other it, the html doc it - is now
          Strict. So thanks Jeff.
          should really read

          Well, "she" (and much more correctly "it") should have changed it - no,
          not me! the other it, the html doc it. It is now Strict. So thanks Jeff.

          --
          dorayme

          Comment

          • maya

            #6
            Re: padding-left, padding-right..

            dorayme wrote:
            In article
            <doraymeRidTh is-95AA2C.15362801 042008@news-vip.optusnet.co m.au>,
            dorayme <doraymeRidThis @optusnet.com.a uwrote:
            >
            >Well, "she" (and much more correctly "it") should have been changed by
            >me to Strict and it - no, not me! the other it, the html doc it - is now
            >Strict. So thanks Jeff.
            >
            should really read
            >
            Well, "she" (and much more correctly "it") should have changed it - no,
            not me! the other it, the html doc it. It is now Strict. So thanks Jeff.
            >
            I see....:) thank you all very much for your responses...


            Comment

            • Jeff

              #7
              Re: padding-left, padding-right..

              dorayme wrote:
              In article
              <doraymeRidTh is-95AA2C.15362801 042008@news-vip.optusnet.co m.au>,
              dorayme <doraymeRidThis @optusnet.com.a uwrote:
              >
              >Well, "she" (and much more correctly "it") should have been changed by
              >me to Strict and it - no, not me! the other it, the html doc it - is now
              >Strict. So thanks Jeff.
              >
              should really read
              >
              Well, "she" (and much more correctly "it") should have changed it - no,
              not me! the other it, the html doc it. It is now Strict. So thanks Jeff.
              Hmm, I don't think we've discussed the gender of html docs before.
              Although I can certainly understand the confusion behind what gender a
              transitional page is!

              Jeff
              >

              Comment

              Working...