Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this Doctype "DIV" not allowed?

I have created this piece of code.

<a href="#">
  <!-- BEGIN #btnBox .btnBox --> 
  <div id="btnBox2" class="btnBox">
    <div class="btnleft"></div> <!-- BEGIN & END .btnleft -->
      <!-- BEGIN .btncenter --> 
      <div class="btncenter">
        <div id="btnText2" class="btnText">Want more? - check out my recent work</div>
      </div>
      <!-- END .btncenter -->            
      <div class="btnright"></div> <!-- BEGIN & END .btnright -->
  </div>
  <!-- END #btnBox .btnBox -->   
</a>

And when I validate the code under W3 HTML validation, it's giving me an error:

Line 163, Column 41: document type does not allow element "DIV" here; missing one of "OBJECT", "MAP", "BUTTON" start-tag

I am using

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
like image 813
Muzammil Avatar asked Jun 03 '11 19:06

Muzammil


People also ask

Which one is a valid HTML tag?

The valid HTML tag must satisfy the following conditions: It should start with an opening tag (<). It should be followed by a double quotes string or single quotes string. It should not allow one double quotes string, one single quotes string or a closing tag (>) without single or double quotes enclosed.

Can we use name attribute in div?

There is no name attribute for div elements. If you want to uniquely identify one, then use id . If you want to mark one as a member of a group, then use class . The only place you can use a name attribute (that hasn't been deprecated) is on form controls ( input , select , textarea and button ).

Can you add name to div?

If you need to 'name' a div in order to address it from javascript or otherwise uniquely identify it on a page, you can use the id attribute. That said, most modern browsers will handle a name attribute on a div with no issues but it does not conform to HTML standards.


2 Answers

Divs are block level elements - they should not be included within Anchor tags.

like image 158
g.d.d.c Avatar answered Oct 16 '22 23:10

g.d.d.c


A division <div> is a block level element while an anchor <a> is an inline element. From the w3c web site:

Generally, block-level elements may contain inline elements and other block-level elements. Generally, inline elements may contain only data and other inline elements. Inherent in this structural distinction is the idea that block elements create "larger" structures than inline elements.

Chances are you're using divisions because you need block-level behavior, like width and height.

Without changing your DOCTYPE, you can use the CSS property display to make <span> elements behave like <div> elements:

HTML

<a href="#" class="forMuzammil">
<!-- BEGIN #btnBox .btnBox --> 
<span id="btnBox2" class="btnBox">
    <span class="btnleft"></span> <!-- BEGIN & END .btnleft -->
    <!-- BEGIN .btncenter --> 
    <span class="btncenter">
        <span id="btnText2" class="btnText">Want more? - check out my recent work</span>
    <!-- END .btncenter -->    
    </span>
    <span class="btnright"></span> <!-- BEGIN & END .btnright -->
<!-- END #btnBox .btnBox -->     
</span>
</a>

CSS

a.forMuzammil {
    display:block;
}
a.forMuzammil span {
    display:block;
}
like image 37
Richard JP Le Guen Avatar answered Oct 16 '22 23:10

Richard JP Le Guen