when I use DOCTYPE, margin and padding are ignored

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

    when I use DOCTYPE, margin and padding are ignored

    Why is it when I have a DOCTYPE line in my HTML then "margin" and
    "padding" are ignored?

    This happens in both inline and stylesheet styles.
    It happens for both XHTML and HTML doctypes.
    It happens in IE6, IE7 and Firefox (didn't try any others).
    And when you save the page, the margin/paddings are actually REMOVED
    from the saved HTML file (!).

    Why is this?

    Here you can see the problem:


    And here there is no DOCTYPE line and so the page is fine:


    Here is my HTML (Valid XHTML 1.0 Strict):

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
    www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <title>Exampl e of DOCTYPE / inline margin issue</title>
    <link href="xhtmlMarg inIssue.css" type="text/css" rel="stylesheet "/>
    </head>
    <body>

    <p>Because I have a DOCTYPE on this page, the <b>margin</band
    <b>padding</bstyles are ignored. Why?<br/>
    <a href="xhtmlMarg inIssueWithoutD octype.htm">If I take the DOCTYPE
    line out then it works.</a></p>

    <div style="margin: 20 20 20 20;background-color:#ddd;font-size:
    24pt;color:red; padding: 100 100 100 100">inside inline-css div </div>
    <p>First sentence outside the divs. </p>

    <div class="message" >inside stylesheet-css div</div>
    <p>Second sentence outside the divs.</p>

    </body>
    </html>

  • Jukka K. Korpela

    #2
    Re: when I use DOCTYPE, margin and padding are ignored

    Scripsit Edward:
    Why is it when I have a DOCTYPE line in my HTML then "margin" and
    "padding" are ignored?
    Because browsers generally behave better (in a more standards-conforming
    way) when a suitable DOCTYPE declaration appears at the start of the
    document. Google for "quirks mode" or go directly to
    http://www.quirksmode.org/css/contents.html for explanations.
    <div style="margin: 20 20 20 20;background-color:#ddd;font-size:
    24pt;color:red; padding: 100 100 100 100">inside inline-css div </div>
    A conforming browser _must_ ignore the margin and padding rules, since the
    specified values are syntactically malformed (no unit symbol after number).
    Of course, this is just the top of the iceberg. Normally you shouldn't use
    pixel values but em values for margin and padding.

    --
    Jukka K. Korpela ("Yucca")


    Comment

    • Andy Dingley

      #3
      Re: when I use DOCTYPE, margin and padding are ignored

      On 20 Mar, 11:51, "Edward" <edw...@tanguay .infowrote:
      Why is it when I have a DOCTYPE line in my HTML then "margin" and
      "padding" are ignored?
      Wrong question. Ask instead, "Why is it that when I _don't_ use a
      doctype declaration, the browser tries to guess at what grossly
      invalid CSS ought to mean and uses that."
      <div style="margin: 20 20 20 20;
      You probably meant
      <div style="margin: 20px 20px 20px 20px;

      Always validate your HTML and CSS before posting questions.
      It will often give you an answer immediately.



      Comment

      • Edward

        #4
        Re: when I use DOCTYPE, margin and padding are ignored

        Always validate your HTML and CSS before posting questions.
        It will often give you an answer immediately.
        The above code validates fine at http://validator.w3.org which I
        assumed was the end-all authority on HTML validation.

        Does anyone know of a more accurate HTML validating service?


        Comment

        • Edward

          #5
          Re: when I use DOCTYPE, margin and padding are ignored

          You probably meant
          <div style="margin: 20px 20px 20px 20px;
          Yes, the "px" identifiers fix it, thanks.
          I'd picked up a bad habit along the way of not including them.

          Edward Tanguay
          All my projects: http://www.tanguay.info


          Comment

          • Andy Dingley

            #6
            Re: when I use DOCTYPE, margin and padding are ignored

            On 20 Mar, 15:20, "Edward" <edw...@tanguay .infowrote:
            Always validate your HTML and CSS before posting questions.
            It will often give you an answer immediately.
            >
            The above code validates fine athttp://validator.w3.or gwhich I
            assumed was the end-all authority on HTML validation.
            It's valid HTML, but it's not valid CSS. You need to check both, and
            usually have to do it separately.

            I stongly recommend using Firefox and the latest HTML validator
            extension.

            This includes a real HTML validator and also Tidy. Because it's
            pervasive and automatic, it also gets used (unlike making the effort
            to use the W3C).

            Comment

            • Edward

              #7
              Re: when I use DOCTYPE, margin and padding are ignored

              I stongly recommend using Firefox and the latest HTML validator
              extension.http://users.skynet.be/mgueury/mozilla/
              This includes a real HTML validator and also Tidy. Because it's
              pervasive and automatic, it also gets used (unlike making the effort
              to use the W3C).
              I installed that, seems to work fine, thanks.

              I checked my above code at http://jigsaw.w3.org/css-validator and the
              pixel errors shows up immediately, very nice.

              I also found and installed this Firefox CSS validator addon (https://
              addons.mozilla. org/firefox/2289) but realized that it simply goes
              online to the above service and hences doesn't work for local files,
              which would be nice when developing, like you say, so it is automatic
              and actually gets used.

              Do you know of any CSS validator addons for Firefox that check LOCAL
              files?

              Edward Tanguay
              All my projects: http://www.tanguay.info


              Comment

              • Johannes Koch

                #8
                Re: when I use DOCTYPE, margin and padding are ignored

                Edward schrieb:
                Do you know of any CSS validator addons for Firefox that check LOCAL
                files?
                With the Web Developer Extension you can check local CSS (via uploading
                the CSS to the W3C's CSS checker). Or do you mean checking while you're
                not online?

                --
                Johannes Koch
                Spem in alium nunquam habui praeter in te, Deus Israel.
                (Thomas Tallis, 40-part motet)

                Comment

                • Edward

                  #9
                  Re: when I use DOCTYPE, margin and padding are ignored

                  With the Web Developer Extension you can check local CSS (via uploading
                  the CSS to the W3C's CSS checker). Or do you mean checking while you're
                  not online?
                  Checking local code while online is ok, I just want to be able to
                  check quickly as I develop.
                  I have the Web Developer Extension but under the CSS dropdown I only
                  find:

                  Disable Styles
                  Disable CSS by Media Type
                  View CSS
                  View Style Information
                  Add User Style Sheet
                  Edit CSS
                  User Border Box Model

                  Is there a selection somewhere to automatically upload the code to the
                  online CSS checker?

                  Edward Tanguay
                  All my projects: http://www.tanguay.info

                  Comment

                  • Johannes Koch

                    #10
                    Re: when I use DOCTYPE, margin and padding are ignored

                    Edward schrieb:
                    I have the Web Developer Extension but under the CSS dropdown I only
                    find:
                    [...]
                    Is there a selection somewhere to automatically upload the code to the
                    online CSS checker?
                    See in the Tools menu: Validate Local CSS

                    --
                    Johannes Koch
                    Spem in alium nunquam habui praeter in te, Deus Israel.
                    (Thomas Tallis, 40-part motet)

                    Comment

                    • livelovelearn@gmail.com

                      #11
                      Re: when I use DOCTYPE, margin and padding are ignored

                      Lately I've seen quite a few references to using em instead of px for
                      margin and padding. Maybe you could explain this because it seems
                      counter intuitive. Let's say you design a page with a 20 em left and
                      right margin and the font is 1 em. Now a user comes along and and
                      needs the largest font size possible. They have their browser to show
                      text as 'Largest'.

                      Now, not only is the text largest, but the margins have also expanded.
                      Because em are used the margin and padding dimension are also larger.
                      The result is that the text is crunched into a smaller space.

                      Of course the opposite is true. The user uses 'Smallest' with the
                      result of shrinking margin and padding dimensions. Wouldn't you want
                      just the opposite.

                      It seems to me that whoever came up with this "use em instead of px
                      for margins and paddings" didn't think it through.

                      On Mar 20, 5:02 am, "Jukka K. Korpela" <jkorp...@cs.tu t.fiwrote:
                      Scripsit Edward:
                      >
                      Why is it when I have a DOCTYPE line in my HTML then "margin" and
                      "padding" are ignored?
                      >
                      Because browsers generally behave better (in a more standards-conforming
                      way) when a suitable DOCTYPE declaration appears at the start of the
                      document. Google for "quirks mode" or go directly tohttp://www.quirksmode. org/css/contents.htmlfo r explanations.
                      >
                      <div style="margin: 20 20 20 20;background-color:#ddd;font-size:
                      24pt;color:red; padding: 100 100 100 100">inside inline-css div </div>
                      >
                      A conforming browser _must_ ignore the margin and padding rules, since the
                      specified values are syntactically malformed (no unit symbol after number).
                      Of course, this is just the top of the iceberg. Normally you shouldn't use
                      pixel values but em values for margin and padding.
                      >
                      --
                      Jukka K. Korpela ("Yucca")http://www.cs.tut.fi/~jkorpela/

                      Comment

                      • Jukka K. Korpela

                        #12
                        Re: when I use DOCTYPE, margin and padding are ignored

                        Scripsit livelovelearn@g mail.com:
                        Lately I've seen quite a few references to using em instead of px for
                        margin and padding. Maybe you could explain this because it seems
                        counter intuitive.
                        Just hang around and you'll learn that, as well as how to post
                        constructively on Usenet (instead of upside-down fullquoting). For fast
                        learning, check past postings via Google Groups or the fine FAQs.
                        Let's say you design a page with a 20 em left and
                        right margin and the font is 1 em.
                        Then you've set the margins too large. Using fine units doesn't mean you can
                        use absurd numbers with them.
                        It seems to me that whoever came up with this "use em instead of px
                        for margins and paddings" didn't think it through.
                        For a person who started posting the way you did, you speculate too much on
                        other people's thinking.

                        --
                        Jukka K. Korpela ("Yucca")


                        Comment

                        • dorayme

                          #13
                          Re: when I use DOCTYPE, margin and padding are ignored

                          In article
                          <1174405688.005 803.192190@e1g2 000hsg.googlegr oups.com>,
                          "Andy Dingley" <dingbat@codesm iths.comwrote:
                          I stongly recommend using Firefox and the latest HTML validator
                          extension.

                          This includes a real HTML validator and also Tidy. Because it's
                          pervasive and automatic, it also gets used (unlike making the effort
                          to use the W3C).
                          Thanks for mentioning this one. I will have it when I can solve
                          the following query:

                          At http://users.skynet.be/mgueury/mozilla/download.html there is
                          a 4 line instruction set and I am stumped by point 3. What
                          exactly does one need to do to "add the website to the authorized
                          list."? I run OS X on Tiger, PPC.

                          I ask here in case someone here has already done this, I have
                          also asked in a Mac group. You see how anxious I am to get it, it
                          is a good idea!

                          --
                          dorayme

                          Comment

                          • Bergamot

                            #14
                            Re: when I use DOCTYPE, margin and padding are ignored

                            livelovelearn@g mail.com wrote:
                            Lately I've seen quite a few references to using em instead of px for
                            margin and padding.
                            It really depends on the design. em scales with text size. % scales with
                            window size. px are fine for padding and even margins, especially if
                            graphics are involved. Personally, I prefer % over em in a lot of cases.

                            You can mix units, but if you don't know what you're doing the layout
                            may suffer.

                            BTW, don't top post.


                            --
                            Berg

                            Comment

                            • Sherm Pendley

                              #15
                              Re: when I use DOCTYPE, margin and padding are ignored

                              dorayme <doraymeRidThis @optusnet.com.a uwrites:
                              In article
                              <1174405688.005 803.192190@e1g2 000hsg.googlegr oups.com>,
                              "Andy Dingley" <dingbat@codesm iths.comwrote:
                              >
                              >I stongly recommend using Firefox and the latest HTML validator
                              >extension.
                              >http://users.skynet.be/mgueury/mozilla/
                              >This includes a real HTML validator and also Tidy. Because it's
                              >pervasive and automatic, it also gets used (unlike making the effort
                              >to use the W3C).
                              >
                              Thanks for mentioning this one. I will have it when I can solve
                              the following query:
                              >
                              At http://users.skynet.be/mgueury/mozilla/download.html there is
                              a 4 line instruction set and I am stumped by point 3. What
                              exactly does one need to do to "add the website to the authorized
                              list."? I run OS X on Tiger, PPC.
                              Bring up the FireFox preferences. In the "Security" pane, the "warn me
                              when sites try to install add-ons" should be checked. Click the button
                              to the right of that, labeled "Exceptions ", and add "users.skynet.b e"
                              to the list of sites that are, as the button's name implies, exceptions
                              to the normal rule and therefore allowed to install add-ons.

                              sherm--

                              --
                              Web Hosting by West Virginians, for West Virginians: http://wv-www.net
                              Cocoa programming in Perl: http://camelbones.sourceforge.net

                              Comment

                              Working...