制作按钮 - <按钮>或< div>? [英] Making buttons - <button> or <div>?
问题描述
我想知道什么html元素用于网页上的按钮 - 我想像Twitter一样设计我的'按钮'。例如:
推特列表底部的更多按钮 - 是<按钮>
元素还是< div>
元素?我想知道使用哪个。我认为对于<按钮>
或< div>
,我们可以提供翻转状态以及所有这些东西它看起来很愉快?
< a>
或<按钮>
元素。这使得禁用JavaScript的浏览器可以按照预期与它们进行交互。即使您的功能需要使用JavaScript,并且没有合理的默认行为,您可以将其分配给< a>
,无论使用它,它都会传达可点击的语义。 > 通常,选择最接近描述其内容的功能的标签,而不是其内容的外观,并避免不必要的< div>
标签,以防您的文件受到 divitis 的伤害。
I'm wondering what html element to use for buttons on a web page - I'd like to style my 'buttons' like twitter does. For example:
the "more" button at the bottom of the tweet listing - is that a <button>
element, or a <div>
element? I'd like to know which to use. I think for either <button>
or <div>
we can supply rollover states and all that stuff to make it look pleasant?
Don't use <div>
tags to make clickable elements. Use <a>
or <button>
elements. This enables browsers with JavaScript disabled to interact with them as expected. Even if your functionality requires JavaScript and there is no reasonable default behaviour you can assign to an <a>
, use it regardless - it conveys "clickable" semantics.
In general, choose the tag that most closely describes the function of its content, not the appearance of its content, and avoid unnecessary <div>
tags lest your documents suffer from divitis.
这篇关于制作按钮 - <按钮>或< div>?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!