實現僅鍵盤焦點樣式
您的目標是在不必要時禁用:focus,因為它在美觀上與活動狀態衝突。但是,您希望為鍵盤使用者保留焦點樣式。這裡有一個解決這個問題的綜合方法:
:focus-visible 解決方案
考慮使用:focus-visible,一個偽類,它在有益於用戶,例如在鍵盤互動期間。現代瀏覽器現在支援這個偽類。
使用:focus-visible,您可以有條件地應用焦點樣式:
<code class="css">button:focus-visible { /* remove default focus style */ outline: none; /* custom focus styles */ box-shadow: 0 0 2px 2px #51a7e8; color: lime; }</code>
瀏覽器相容性
不支援:focus -visible 的瀏覽器可能仍會顯示預設對焦環。為了確保行為一致,請使用後備策略:
<code class="css">button:focus { outline: none; background: #ffdd00; /* gold */ } button:focus:not(:focus-visible) { background: white; /* undo gold */ }</code>
僅鍵盤焦點樣式
對於僅鍵盤焦點樣式解決方案,請考慮使用以下方法:
<code class="css">button { -moz-appearance: none; -webkit-appearance: none; background: none; border: none; outline: none; font-size: inherit; } .btn { all: initial; margin: 1em; display: inline-block; } .btn__content { background: orange; padding: 1em; cursor: pointer; display: inline-block; } /* Fixing the Safari bug for `<button>`s overflow */ .btn__content { position: relative; } /* All the states on the inner element */ .btn:hover > .btn__content { background: salmon; } .btn:active > .btn__content { background: darkorange; } .btn:focus > .btn__content { box-shadow: 0 0 2px 2px #51a7e8; color: lime; } /* Removing default outline only after we've added our custom one */ .btn:focus, .btn__content:focus { outline: none; }</button></code>
此方法在每個按鈕/連結/等中使用內部元素()。並設定該內部元素的 tabindex。焦點樣式僅套用於內部元素,確保它們僅出現在鍵盤焦點上。
以上是如何在不影響視覺美觀的情況下實現純鍵盤對焦風格?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

重構自己的代碼看起來是什麼樣的?約翰·瑞亞(John Rhea)挑選了他寫的一個舊的CSS動畫,並介紹了優化它的思維過程。

CSSanimationsarenotinherentlyhardbutrequirepracticeandunderstandingofCSSpropertiesandtimingfunctions.1)Startwithsimpleanimationslikescalingabuttononhoverusingkeyframes.2)Useeasingfunctionslikecubic-bezierfornaturaleffects,suchasabounceanimation.3)For

@keyframesispopularduetoitsversatoryand and powerincreatingsmoothcsssanimations.keytricksinclude:1)definingsmoothtransitionsbetnestates,2)使用AnimatingMultatingMultationMultationProperPertiessimultane,3)使用使用4)使用BombingeNtibalibility,4)使用CombanningWiThjavoFofofofoftofofo

CSSCOUNTERSAREDOMANAGEAUTOMANAMBERINGINWEBDESIGNS.1)他們可以使用forterablesofcontents,ListItems,and customnumbering.2)AdvancedsincludenestednumberingSystems.3)挑戰挑戰InclassINCludeBrowsEccerCerceribaliblesibility andperformiballibility andperformissises.4)創造性

使用滾動陰影,尤其是對於移動設備,是克里斯以前涵蓋的一個微妙的UX。傑夫(Geoff)涵蓋了一種使用動畫限制屬性的新方法。這是另一種方式。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

禪工作室 13.0.1
強大的PHP整合開發環境

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!