开发者

Is applying styles to <form> element a good practice? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, ar开发者_开发问答guments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

Applying styles to <form> tag is:

a) a good practice, it decreases the count of elements on a page and makes code clear

b) a bad practice because of semantics, use other elements instead, div is for style, form is for forms

c) don't ask silly questions and focus on real job!


d) none of the above

Style the form if that makes life easier for you. It is not against semantics if you do it.


a - Decreasing the amount of elements is not necessarily a good practice. If creating more elements will make your layout more readable/understandable then go ahead.

b - Divs are not for styling, they are there to divide sections in the document

c - You should worry about semantics. This is not a silly question.


a) Yes.

b) No. Div is a generic element. It is not for "style" it is for "when nothing else describes the semantics".


A and C. Simple way checking for good answer is: Write a code and validate it with validator.


Since semantics are seperate from style, applying style to a form has no semantic consequences. Go right ahead and style a form if you like, it makes no difference to the semantic meaning of the page.


In my personal experience, (a) is especially true because:

  • You will be reducing the overall filesize of your page, with no real disadvantage (especially if you have multiple forms and run into this a lot).
  • You will be reducing the amount of confusion when you have to go back to edit this style in the future (where someone may have the same question as you).
  • You will be reducing the ambiguity as to where certain styles come from (e.g. this form has too large of a top margin. Is that coming from the margin on the <div> or the margin on the <form>?)
  • You will be reducing the possibility of introducing bugs or cross-browser quirks, stemming from browsers not implementing the same default styles on all elements (in this case, the <form> element).

While I suppose one could argue that (b) is a "problem" in theory (and should therefore be avoided), it will never be a "problem" in practice. But as you can see above, wrapping it in a <div> can certainly be a problem in practice.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜