I am trying to display a div
using :checked
. I can do this using a checkbox, like so
option:checked {
height: 100px;
width: 100px;
}
.tester {
display: none;
}
select[name=test] option[value=volvo]:checked {
width: 500px;
background-color: red;
font-size: 10px;
display: block;
}
input[type=checkbox]+label {
color: #ccc;
font-style: italic;
}
input[type=checkbox]:checked+div {
color: #f00;
font-style: normal;
display: block;
}
div {
display: none
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<select name='test'>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
<div>
HI THERE
</div>
<input type="checkbox" id="ossm" name="ossm">
<div class='tester'>
HELLO
</div>
<label for="ossm">CSS is Awesome</label>
</body>
</html>
When I check the checkbox, the HELLO
div appears.
When I select volvo
in the select
, it does not display the HI THERE
div.
Am I missing something?
This is just sample code, but the code I am using is a select box that is dynamically created from django
.
Should I use something other than a select/option
combination here if I want this to work?
You can paste the above code into this to make it work
https://www.w3schools.com/cssref/tryit.asp?filename=trycss3_checked2