Regrettably, CSS does not provide a direct way to target an element's parent. In this scenario, the parent element is the select
and its child is the selected option
.
If you want to style the select
based on the selected option
, you'll have to turn to JavaScript:
var select = document.querySelector("select");
select.addEventListener("change", function() {
var selected = document.querySelector("option:checked");
var selectedFontSize = getComputedStyle(selected, null).getPropertyValue("font-size");
select.style.fontSize = selectedFontSize;
});
/* CSS styles for different options */
option.w1 {
font-size: 5px;
background-repeat: repeat;
display: inline-block;
position: static;
}
option.w2 {
font-size:8px;
background-repeat: repeat;
display: inline-block;
position: static;
}
/* Additional option styling goes here */
<div class="row add-top-margin">
<div class="col-xs-3 section-label">Width</div>
<select>
<option class="w1">────</option>
<option class="w2">────</option>
<option class="w3">────</option>
<option class="w4">────</option>
<option class="w5">────</option>
<option class="w6">────</option>
</select>
</div>