Is there a CSS-only way to style a
Table Of Content
Example HTML file:
[pastacode lang=”markup” manual=”%3C!DOCTYPE%20HTML%20PUBLIC%20%22-%2F%2FW3C%2F%2FDTD%20HTML%204.01%2F%2FEN%22%20%22http%3A%2F%2Fwww.w3.org%2FTR%2Fhtml4%2Fstrict.dtd%22%3E%0A%3Chtml%3E%0A%3Chead%3E%0A%20%20%3Ctitle%3ESelect%20Styling%3C%2Ftitle%3E%0A%20%20%3Clink%20href%3D%22selectExample.css%22%20rel%3D%22stylesheet%22%3E%0A%3C%2Fhead%3E%0A%3Cbody%3E%0A%3Cselect%20id%3D%22styledSelect%22%20class%3D%22blueText%22%3E%0A%20%20%3Coption%20value%3D%22apple%22%3EApple%3C%2Foption%3E%0A%20%20%3Coption%20value%3D%22orange%22%3EOrange%3C%2Foption%3E%0A%20%20%3Coption%20value%3D%22cherry%22%3ECherry%3C%2Foption%3E%0A%3C%2Fselect%3E%0A%3C%2Fbody%3E%0A%3C%2Fhtml%3E%0A” message=”html code” highlight=”” provider=”manual”/] [ad type=”banner”]Example CSS file:
[pastacode lang=”css” manual=”%2F*%20All%20select%20elements%20on%20page%20*%2F%0Aselect%20%0A%7B%0A%20%20position%3A%20relative%3B%0A%7D%0A%0A%2F*%20Style%20by%20class.%20Effects%20the%20text%20of%20the%20contained%20options.%20*%2F%0A.blueText%20%0A%7B%0A%20%20color%3A%20%230000FF%3B%0A%7D%0A%0A%2F*%20Style%20by%20id.%20Effects%20position%20of%20the%20select%20drop%20down.%20*%2F%0A%23styledSelect%20%0A%7B%0A%20%20left%3A%20100px%3B%0A%7D%0A” message=”css code” highlight=”” provider=”manual”/]You may style any HTML element by its tag name:
[pastacode lang=”css” manual=”select%20%0A%7B%0A%20%20font-weight%3A%20bold%3B%0A%7D” message=”css code” highlight=”” provider=”manual”/]you can also use a CSS class to style, like any other element:
[pastacode lang=”markup” manual=”%3Cselect%20class%3D%22important%22%3E%0A%20%20%3Coption%3EImportant%20Option%3C%2Foption%3E%0A%20%20%3Coption%3EAnother%20Important%20Option%3C%2Foption%3E%0A%3C%2Fselect%3E%0A%0A%3Cstyle%20type%3D%22text%2Fcss%22%3E%0A%20%20.important%20%0A%7B%0A%20%20%20%20font-weight%3A%20bold%3B%0A%7D%0A%3C%2Fstyle%3E%0A” message=”html code” highlight=”” provider=”manual”/]Styling Select Box with CSS3:
- HTML:
- CSS:
How to CSS form drop down style without using JavaScript .
[pastacode lang=”css” manual=”select%20%0A%7B%0A%20%20%20%20border%3A%200%20none%3B%0A%20%20%20%20color%3A%20%23000%3B%0A%20%20%20%20background%3A%20transparent%3B%0A%20%20%20%20font-size%3A%2020px%3B%0A%20%20%20%20font-weight%3A%20bold%3B%0A%20%20%20%20padding%3A%202px%2010px%3B%0A%20%20%20%20width%3A%20378px%3B%0A%20%20%20%20*width%3A%20350px%3B%0A%20%20%20%20*background%3A%20%2358B14C%3B%0A%7D%0A%23mainselection%20%7B%0A%20%20%20%20overflow%3A%20hidden%3B%0A%20%20%20%20width%3A%20350px%3B%0A%20%20%20%20-moz-border-radius%3A%209px%209px%209px%209px%3B%0A%20%20%20%20-webkit-border-radius%3A%209px%209px%209px%209px%3B%0A%20%20%20%20border-radius%3A%209px%209px%209px%209px%3B%0A%20%20%20%20box-shadow%3A%201px%201px%2011px%20%23330033%3B%0A%20%20%20%20background%3A%20url(%22arrow.gif%22)%20no-repeat%20scroll%20319px%205px%20%2358B14C%3B%0A%7D%0A%3Cdiv%20id%3D%22mainselection%22%3E%0A%20%20%20%20%3Cselect%3E%0A%20%20%20%20%3Coption%3ESelect%20an%20Option%3C%2Foption%3E%0A%20%20%20%20%3Coption%3EOption%201%3C%2Foption%3E%0A%20%20%20%20%3Coption%3EOption%202%3C%2Foption%3E%0A%20%20%20%20%3C%2Fselect%3E%3C%2Fdiv%3E%0A” message=”css code” highlight=”” provider=”manual”/]As of Internet Explorer 10, you can use the ::-ms-expand pseudo element selector to style, and hide, the drop down arrow element.
[pastacode lang=”css” manual=”select%3A%3A-ms-expand%20%0A%7B%0A%20%20%20%20display%3Anone%3B%0A%20%20%20%20%2F*%20or%20visibility%3A%20hidden%3B%20to%20keep%20it’s%20space%2Fhitbox%20*%2F%0A%7D%0A” message=”css code” highlight=”” provider=”manual”/]- The largest variation we have noticed when styling select drop-downs is Safari and Google Chrome rendering (Firefox is fully customizable through CSS).
- Here the simplest solution by using WebKit:
- It removes the dropdown arrow.
- You can add a dropdown arrow using a nearby div with a background, negative margin or absolutely positioned over the select dropdown.
Select dropdown style:
Css:
[pastacode lang=”css” manual=”select%20%20%7B%0A%20%20%20%20outline%3A%200%3B%0A%20%20%20%20overflow%3A%20hidden%3B%0A%20%20%20%20height%3A%2030px%3B%0A%20%20%20%20background%3A%20%232c343c%3B%0A%20%20%20%20color%3A%20%23747a80%3B%0A%20%20%20%20border%3A%20%232c343c%3B%0A%20%20%20%20padding%3A%205px%203px%205px%2010px%3B%0A%20%20%20%20-moz-border-radius%3A%206px%3B%0A%20%20%20%20-webkit-border-radius%3A%206px%3B%0A%20%20%20%20border-radius%3A%2010px%3B%0A%7D%0Aselect%20option%20%7Bborder%3A%201px%20solid%20%23000%3B%20background%3A%20%23010%3B%7D%0A” message=”css code” highlight=”” provider=”manual”/] [ad type=”banner”]- It uses rotated background layers to cut out a dropdown arrow, as pseudo-elements wouldn’t work for the select element.
- Css:
- Using Bootstrap(http://getbootstrap.com/).
- This is the simplest solution :
- It can be improved with hover-effects and other mouse events.
- Just make sure that the “button“-element comes right after the select element in the markup. Then target it using the + css-selector
- HTML:
- CSS:
