Short tags

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    Short tags

    I'm having a problem with the way a page is being rendered in IE7 (of course) and I decided to run the page source through the W3C validation tool.

    I fixed all of the errors and warnings listed for the page (which isn't easy when your page's content is generated by ASP.NET) . This didn't fix the problem in IE7.

    The doctype that ASP.NET uses by default is:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    I decided to switch the doctype to:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" 
    "http://www.w3.org/TR/html4/strict.dtd">

    I ran the page with the new doctype through the W3C validation tool and found a bunch of new errors.

    One of the errors is:
    enabling start-tag requires SHORTTAG YES


    I was under the impression (maybe I learned this when I learned about XML) that you should always close your element tags...and if they are empty you can just use "/>" to end it.

    For example:
    <br />


    Apparently this is not the case with HTML...
    My findings online are that you should use XHTML if you want to use "shorttags" . I didn't think that IE supported XHTML....

    So why would ASP.NET generate HTML that uses short tags?
    Oh never mind that question (stupid MS)


    How do I turn on "shorttags" ?

    Thanks

    -Frinny
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by Frinavale
    One of the errors is:
    enabling start-tag requires SHORTTAG YES

    I was under the impression (maybe I learned this when I learned about XML) that you should always close your element tags...and if they are empty you can just use "/>" to end it.

    For example:
    <br />
    <tag/> is only required in XML, HTML uses <tag> instead, although browsers don’t care whether you write one or the other.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Dorm I don't really have the option of removing the closing "/" because I do not have control over the HTML that is generated by ASP.NET controls.

      I suppose I'll just go back to the default doctype.

      Thanks

      -Frinny

      Comment

      • drhowarddrfine
        Recognized Expert Expert
        • Sep 2006
        • 7434

        #4
        The short tag is because the element is being closed by the /> before it should be, hence the term. Apparently it's one of the vagaries of .NET stuff that they let that happen.

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Today is one of those days when I hate Microsoft with every fiber in my body.
          Hopefully this feeling wares off quickly.

          I found my problem. It has to do with how IE7 treats elements with 'float' styles. It's fixed now but the journey through validation was enough to make the weak minded crazy.

          I need a tea!

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            I don't get it Doc...

            It's complaining about any empty element that is closed.
            Like my example of <br />

            It is not closed "too early", it is simply closed.

            I haven't read the specifications for the DTD but it appears that you aren't supposed to close empty HTML elements....

            I'll have to look into this when I don't have a headache from trying to debug this minor, but very irritating bug in IE7.

            -Frinny

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              Originally posted by Frinavale
              I haven't read the specifications for the DTD but it appears that you aren't supposed to close empty HTML elements....
              empty elements in HTML are defined as such in the DTD only. in the source code they look like opening tags. thus <br/>, <img … />, <hr/> <meta … /> and the like are invalid HTML.

              mind that HTML is *not* a subset of XML (that’s why XHTML was created)

              Comment

              • drhowarddrfine
                Recognized Expert Expert
                • Sep 2006
                • 7434

                #8
                Yeah. What he said.

                It sounds like you're getting more into the bowels of real coding and not letting MS software cover things up for you, Frinny. Is that why you're seeing more of this?

                Comment

                Working...