Is it bad design to use table tags when displaying forms in html?

前端 未结 12 1657
长情又很酷
长情又很酷 2020-11-30 05:01

I keep hearing that div tags should be used for layout purposes and not table tags. So does that also apply to form layout? I know a form layout is

12条回答
  •  隐瞒了意图╮
    2020-11-30 05:42

    I think it's a myth that forms are "difficult" to layout nicely with good HTML and CSS. The level of control that CSS gives you over your layout goes way beyond what any clunky table-based layout ever would. This isn't a new idea, as this Smashing Magazine article from way back in 2006 shows.

    I tend to use variants of the following markup in my forms. I have a generic .form style in my CSS and then variants for text inputs, checkboxes, selects, textareas etc etc.

    .field label {
      float: left;
      width: 20%;
    }
    
    .field.text input {
      width: 75%;
      margin-left: 2%;
      padding: 3px;
    }

    Tables aren't evil. They are by far the best option when tabular data needs to be displayed. Forms IMHO aren't tabular data - they're forms, and CSS provides more than enough tools to layout forms however you like.

提交回复
热议问题