Created
August 1, 2021 21:52
-
-
Save pbuzdin/78563552792509396241ad0bfd7db398 to your computer and use it in GitHub Desktop.
custom dropdown without javascript // source https://jsbin.com/vigacav
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>custom dropdown without javascript</title> | |
<style id="jsbin-css"> | |
body { | |
background-color: rgb(1,1,1); | |
height: 100vh; | |
font-family: sans-serif; | |
padding: 5rem; | |
} | |
details { | |
position: relative; | |
width: 300px; | |
} | |
details[open] { | |
z-index: 1; | |
} | |
summary { | |
cursor: pointer; | |
background-color: cyan; | |
list-style: none; | |
} | |
summary::-webkit-details-marker { | |
display: none; | |
} | |
summary:after { | |
content: ''; | |
float: right; | |
width: .5rem; | |
height: .5rem; | |
border-bottom: 1px solid currentColor; | |
border-left: 1px solid currentColor; | |
border-bottom-left-radius: 2px; | |
transform: rotate(135deg) translate(100%, 0%); | |
transform-origin: center center; | |
transition: transform .4s; | |
background: coral; | |
} | |
summary:focus { | |
outline: none; | |
} | |
details[open] summary:after { | |
transform: rotate(-45deg) translate(-100%, 0%);} | |
.list { | |
width: 100%; | |
position: absolute; | |
max-height: 500px; | |
overflow-y: auto; | |
display: flex; | |
flex-direction: column; | |
} | |
.radios input { | |
pointer-events: none; | |
} | |
input[type=radio] { | |
appearance: none; | |
-webkit-appearance: none; /* safari hui sasari */ | |
display: none; | |
} | |
input[type=radio]:checked { | |
display: inline-block; | |
background: coral; | |
} | |
input[type=radio]:after { | |
content: attr(title); | |
display: inline-block; | |
} | |
label { | |
width: 100%; | |
background: pink; | |
cursor: pointer; | |
} | |
</style> | |
</head> | |
<body> | |
<details class="custom-select"> | |
<summary class="radios"> | |
<input type="radio" name="item" id="default" title="Auswählen..." checked> | |
<input type="radio" name="item" id="item1" title="Item 1"> | |
<input type="radio" name="item" id="item2" title="Item 2"> | |
<input type="radio" name="item" id="item3" title="Item 3"> | |
<input type="radio" name="item" id="item4" title="Item 4"> | |
<input type="radio" name="item" id="item5" title="Item 5"> | |
</summary> | |
<div class="list"> | |
<label for="item1">Item 1</label> | |
<label for="item2">Item 2</label> | |
<label for="item3">Item 3</label> | |
<label for="item4">Item 4</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
<label for="item5">Item 5</label> | |
</div> | |
</details> | |
<script id="jsbin-source-css" type="text/css"> | |
body { | |
background-color: rgb(1,1,1); | |
height: 100vh; | |
font-family: sans-serif; | |
padding: 5rem; | |
} | |
details { | |
position: relative; | |
width: 300px; | |
} | |
details[open] { | |
z-index: 1; | |
} | |
summary { | |
cursor: pointer; | |
background-color: cyan; | |
list-style: none; | |
} | |
summary::-webkit-details-marker { | |
display: none; | |
} | |
summary:after { | |
content: ''; | |
float: right; | |
width: .5rem; | |
height: .5rem; | |
border-bottom: 1px solid currentColor; | |
border-left: 1px solid currentColor; | |
border-bottom-left-radius: 2px; | |
transform: rotate(135deg) translate(100%, 0%); | |
transform-origin: center center; | |
transition: transform .4s; | |
background: coral; | |
} | |
summary:focus { | |
outline: none; | |
} | |
details[open] summary:after { | |
transform: rotate(-45deg) translate(-100%, 0%);} | |
.list { | |
width: 100%; | |
position: absolute; | |
max-height: 500px; | |
overflow-y: auto; | |
display: flex; | |
flex-direction: column; | |
} | |
.radios input { | |
pointer-events: none; | |
} | |
input[type=radio] { | |
appearance: none; | |
-webkit-appearance: none; /* safari hui sasari */ | |
display: none; | |
} | |
input[type=radio]:checked { | |
display: inline-block; | |
background: coral; | |
} | |
input[type=radio]:after { | |
content: attr(title); | |
display: inline-block; | |
} | |
label { | |
width: 100%; | |
background: pink; | |
cursor: pointer; | |
}</script> | |
</body> | |
</html> |
This file contains 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
body { | |
background-color: rgb(1,1,1); | |
height: 100vh; | |
font-family: sans-serif; | |
padding: 5rem; | |
} | |
details { | |
position: relative; | |
width: 300px; | |
} | |
details[open] { | |
z-index: 1; | |
} | |
summary { | |
cursor: pointer; | |
background-color: cyan; | |
list-style: none; | |
} | |
summary::-webkit-details-marker { | |
display: none; | |
} | |
summary:after { | |
content: ''; | |
float: right; | |
width: .5rem; | |
height: .5rem; | |
border-bottom: 1px solid currentColor; | |
border-left: 1px solid currentColor; | |
border-bottom-left-radius: 2px; | |
transform: rotate(135deg) translate(100%, 0%); | |
transform-origin: center center; | |
transition: transform .4s; | |
background: coral; | |
} | |
summary:focus { | |
outline: none; | |
} | |
details[open] summary:after { | |
transform: rotate(-45deg) translate(-100%, 0%);} | |
.list { | |
width: 100%; | |
position: absolute; | |
max-height: 500px; | |
overflow-y: auto; | |
display: flex; | |
flex-direction: column; | |
} | |
.radios input { | |
pointer-events: none; | |
} | |
input[type=radio] { | |
appearance: none; | |
-webkit-appearance: none; /* safari hui sasari */ | |
display: none; | |
} | |
input[type=radio]:checked { | |
display: inline-block; | |
background: coral; | |
} | |
input[type=radio]:after { | |
content: attr(title); | |
display: inline-block; | |
} | |
label { | |
width: 100%; | |
background: pink; | |
cursor: pointer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment