Is it correct to use DIV inside FORM?

前端 未结 10 1607
旧巷少年郎
旧巷少年郎 2020-12-02 17:51

I\'m just wondering what are you thinking about DIV-tag inside FORM-tag?

I need something like this:

&l
相关标签:
10条回答
  • 2020-12-02 18:37

    Definition and Usage

    The tag defines a division or a section in an HTML document.

    The tag is used to group block-elements to format them with styles. http://www.w3schools.com/tags/tag_div.asp

    Also DIV - MDN

    The HTML element (or HTML Document Division Element) is the generic container for flow content, which does not inherently represent anything. It can be used to group elements for styling purposes (using the class or id attributes), or because they share attribute values, such as lang. It should be used only when no other semantic element (such as or ) is appropriate.

    You can use div inside form, if you are talking about using div instead of table, then google about Tableless web design

    0 讨论(0)
  • 2020-12-02 18:40

    It is completely acceptable to use a DIV inside a <form> tag.

    If you look at the default CSS 2.1 stylesheet, div and p are both in the display: block category. Then looking at the HTML 4.01 specification for the form element, they include not only <p> tags, but <table> tags, so of course <div> would meet the same criteria. There is also a <legend> tag inside the form in the documentation.

    For instance, the following passes HTML4 validation in strict mode:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
    <html>
    <head>
    <META http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Test</title>
    </head>
    <body>
    <form id="test" action="test.php">
    <div>
      Test: <input name="blah" value="test" type="text">
    </div>
    </form>
    </body>
    </html>
    
    0 讨论(0)
  • 2020-12-02 18:44

    Your question doesn't address what you want to put in the DIV tags, which is probably why you've received some incomplete/wrong answers. The truth is that you can, as Royi said, put DIV tags inside of your forms. You don't want to do this for labels, for instance, but if you have a form with a bunch of checkboxes that you want to lay out into three columns, then by all means, use DIV tags (or SPAN, HEADER, etc.) to accomplish the look and feel you're trying to achieve.

    0 讨论(0)
  • 2020-12-02 18:49

    Absolutely not! It will render, but it will not validate. Use a label.

    It is not correct. It is not accessible. You see it on some websites because some developers are just lazy. When I am hiring developers, this is one of the first things I check for in candidates work. Forms are nasty, but take the time and learn to do them properly

    0 讨论(0)
提交回复
热议问题