制作按钮 - <按钮>或< div>? [英] Making buttons - <button> or <div>?

查看:75
本文介绍了制作按钮 - <按钮>或< div>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道什么html元素用于网页上的按钮 - 我想像Twitter一样设计我的'按钮'。例如:



http://twitter.com/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:

http://twitter.com/twitter

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.

这篇关于制作按钮 - &lt;按钮&gt;或&lt; div&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆