如何建立以圖像作為選項的下拉選擇
您想要實現一個以圖像而不是文字作為選項的下拉選擇。雖然使用 jQuery 組合框可能是一個流行的建議,但它保留文字作為主要選項,並僅使用圖像作為隨附圖示。然而,您的要求是讓圖像完全替換任何文字。
幸運的是,您甚至無需使用 JavaScript 即可實現此解決方案。操作方法如下:
HTML 結構:
<div> <p>在此結構中,我們使用單選按鈕作為下拉清單中的「選項」。當您點擊連結的標籤時,它們將啟動單選按鈕,從而建立下拉清單的功能。 </p> <p><strong>CSS 樣式:</strong></p> <pre class="brush:php;toolbar:false">/* Style the overall dropdown box */ #image-dropdown { border: 1px solid black; width: 200px; height: 50px; overflow: hidden; transition: height 0.1s; /* Hide when collapsed */ } /* Style the dropdown when expanded */ #image-dropdown:hover { height: 200px; overflow-y: scroll; /* Allow scrolling */ transition: height 0.5s; } /* Hide the radio button visuals */ #image-dropdown input { position: absolute; top: 0; left: 0; opacity: 0; } /* Style the dropdown options */ #image-dropdown label { display: none; margin: 2px; height: 46px; opacity: 0.2; background: url("http://www.google.com/images/srpr/logo3w.png") 50% 50%; } #image-dropdown:hover label { display: block; /* Show all options when expanded */ } /* Show the option related to the selected radio button */ #image-dropdown input:checked + label { opacity: 1 !important; display: block; }
此樣式操作元素的可見性和樣式,創建以圖像作為選項的下拉選擇的錯覺。
您可以自訂http://jsfiddle.net/NDCSR/1/ 提供的範例以滿足您的特定需求,例如使用基於「for」屬性值的標籤選擇器來不同地設定每個選項的背景圖像。
以上是如何在不使用 JavaScript 的情況下建立以圖像作為選項的下拉選擇?的詳細內容。更多資訊請關注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
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

Atom編輯器mac版下載
最受歡迎的的開源編輯器

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境