-1

I would like the first-child in the option to have a different font-size. I'm trying various methods but it isn't happening. So far, I've got this:

JSFiddle: https://jsfiddle.net/2n9cfyo0/1/

I want it to appear this way by default (this is the first-child):

enter image description here

but change the font-size to 24px when the dropdown is chosen:

enter image description here

select {
  -moz-appearance: none;
  -webkit-appearance: none;
  appearance: none;
  padding: 7px 15px;
  border: 1px solid #333;
  border-radius: 2px;
  font-size: 24px;
}

.target option:first-child {
  font-size: 12;
}
<select class="target">
  <option value="">select</option>
  <option value="1">option 1</option>
  <option value="2">option 2</option>
</select>
mplungjan
  • 169,008
  • 28
  • 173
  • 236
Elaine Byene
  • 3,868
  • 12
  • 50
  • 96

1 Answers1

2

I've created a jsfiddle to achieve the same result that is required. It would require javascript & jquery to achieve the result you're expecting. Changing the dropdown from one form to another is an Event, and Events exists in Jquery, in your case, we've to use .change() event.

Add the below javascript code :

$(".target").change(function(){
   if (this.value == "2") {
     $(this).css({"font-size" : "34px"});
   }
});

the above code says that when you select Option 2 from the dropdown, it would change the size of font to 34px;, you can modify the fiddle according to your needs :)

$(".target").change(function() {
  if (this.value == "2") {
    $(this).css({
      "font-size": "34px"
    });
  }
});
select {
  -moz-appearance: none;
  -webkit-appearance: none;
  appearance: none;
  padding: 7px 15px;
  border: 1px solid #333;
  border-radius: 2px;
  font-size: 24px;
}

.target option:first-child {
  font-size: 12;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select class="target">
  <option value="">select</option>
  <option value="1">option 1</option>
  <option value="2">option 2</option>
</select>
mplungjan
  • 169,008
  • 28
  • 173
  • 236
Bilal Ahmed
  • 1,043
  • 4
  • 17
  • 32
  • Thanks. I made some changes to make it work the way I want `if (document.getElementById("dropdown_change").value != "")` and it's working well. however, When I choose `select`, it doesn't revert to the original size. Any idea? – Elaine Byene Oct 15 '19 at 11:31
  • 1
    @ElaineByene Here is my updated [fiddle](https://jsfiddle.net/nm10fkrc/) . If this solution worked, don't forget to up vote too :D – Bilal Ahmed Oct 15 '19 at 11:48