Created
February 18, 2014 17:37
-
-
Save fritids/9075733 to your computer and use it in GitHub Desktop.
Styling Select Box with CSS3 see : http://cssdeck.com/labs/styling-select-box-with-css3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* The CSS */ | |
| select { | |
| padding:3px; | |
| margin: 0; | |
| -webkit-border-radius:4px; | |
| -moz-border-radius:4px; | |
| border-radius:4px; | |
| -webkit-box-shadow: 0 3px 0 #ccc, 0 -1px #fff inset; | |
| -moz-box-shadow: 0 3px 0 #ccc, 0 -1px #fff inset; | |
| box-shadow: 0 3px 0 #ccc, 0 -1px #fff inset; | |
| background: #f8f8f8; | |
| color:#888; | |
| border:none; | |
| outline:none; | |
| display: inline-block; | |
| -webkit-appearance:none; | |
| -moz-appearance:none; | |
| appearance:none; | |
| cursor:pointer; | |
| } | |
| /* Targetting Webkit browsers only. FF will show the dropdown arrow with so much padding. */ | |
| @media screen and (-webkit-min-device-pixel-ratio:0) { | |
| select {padding-right:18px} | |
| } | |
| label {position:relative} | |
| label:after { | |
| content:'<>'; | |
| font:11px "Consolas", monospace; | |
| color:#aaa; | |
| -webkit-transform:rotate(90deg); | |
| -moz-transform:rotate(90deg); | |
| -ms-transform:rotate(90deg); | |
| transform:rotate(90deg); | |
| right:8px; top:2px; | |
| padding:0 0 2px; | |
| border-bottom:1px solid #ddd; | |
| position:absolute; | |
| pointer-events:none; | |
| } | |
| label:before { | |
| content:''; | |
| right:6px; top:0px; | |
| width:20px; height:20px; | |
| background:#f8f8f8; | |
| position:absolute; | |
| pointer-events:none; | |
| display:block; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <label> | |
| <select> | |
| <option selected> Select Box </option> | |
| <option>Short Option</option> | |
| <option>This Is A Longer Option</option> | |
| </select> | |
| </label> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Damoin Yeatman is responsible for this little experiment where he tried to prettify the default select form control with some CSS3 love. The best part about this item is the custom arrows in the select box. It's a neat little trick where the author rotated '<>' by 90 degrees with CSS3 transforms.
Note pointer-events: none; on the :after pseudo element is quite important to make sure that the dropdown opens when the arrows are clicked. It makes sure that the pseudo element does not receive any hover/click event, instead the event occurs on what is behind it, i.e., the label element.