問題描述
這可能是一個固執(zhí)己見的問題,但我環(huán)顧網(wǎng)絡(luò),似乎網(wǎng)絡(luò)開發(fā)人員喜歡將 <a>
標記設(shè)置為看起來像按鈕,而不是使用特定的 <按鈕>
標簽.我在查看導(dǎo)航時明顯看到了這一點
This may be an opinionated question, but I was looking around the web and it seems like web developers like to style <a>
tags to look like buttons, rather than use a specific <button>
tag. I've noticeably seen this when looking at navigations
經(jīng)過一番研究,我發(fā)現(xiàn)了這個:
After a bit of research, I found this:
- 按鈕不適合搜索,因為其中的文本對搜索引擎是不可見的.
- 按鈕比鏈接更難更新,每次更新都需要 Photoshop 和新圖片.
- 按鈕加載速度比鏈接慢,這對移動訪問者尤其不利.
- 視覺障礙者不太容易使用按鈕.
- 按鈕是不必要的,即使你想使用非標準字體,這要歸功于 TypeKit 等工具.~ 引用自這里
但是,這些原因"中的大多數(shù)似乎都非常站不住腳,并且您需要 photoshop"之類的答案似乎……嗯……無效?
However, most of these 'reasons' seems quite flimsy and answers like 'you need photoshop' seem... well... invalid?
所以我想知道:
在創(chuàng)建導(dǎo)航菜單時不使用 <button>
標簽是否有實際原因,而是將 <a>
標簽設(shè)置為看起來像按鈕?為什么按鈕不是常態(tài)?這不是他們的目的嗎?
Is there an actual reason why the <button>
tags aren't used when creating navigation menus, and instead style <a>
tags to look like buttons?
Why aren't buttons the norm? Is this not what they're made for?
* 我不希望你在這里發(fā)表意見,也不希望有觀點.僅關(guān)于為什么會這樣的事實信息
推薦答案
閱讀了評論中發(fā)布的多個文檔后,似乎確實有一個明確的事實原因按鈕沒有使用導(dǎo)航欄.
After reading up on multiple documents posted in the comments, it seems that there is actually a clear factual reason buttons are not used in navigation bars.
當存在頁面重定向或?qū)⒂脩魩У骄W(wǎng)站的其他位置時使用這些.
These are used when there is a page redirect or taking a user elsewhere on the website.
- 如果它導(dǎo)航,它就是一個鏈接.使用具有有效超文本引用的鏈接標記
~鏈接不是按鈕
按鈕元素
當您想要doSomething() 即不 重定向用戶時使用這些.IE.提交表單/等.
Button elements
These are used when you want to doSomething() that is not redirecting the user. I.e. submitting a form / etc.
你需要問自己的問題是:
The question you need to ask yourself is:
此控件是否用于啟動即時操作或該操作是導(dǎo)航到另一個頁面嗎?
Will this control be used to initiate an immediate action or Is the action to navigate to another page?
如果您的問題的答案是第一部分,那么您應(yīng)該使用 button
元素.而如果您希望使用后者,那么您應(yīng)該使用 a
元素.
if the answer to your question is the first part, then you should be using a button
element. Whereas if it is the latter that you are wishing to do, then you should be using an a
element.
進一步閱讀:
w3.org
鏈接不是按鈕.DIV 和 SPAN 也不是
何時使用按鈕元素
這篇關(guān)于為什么不鼓勵按鈕導(dǎo)航?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!