0

I have a dropdown where I need to make first value in the dropdown to be bold.Dropdown code is as follows.

<div class="col-xs-3">
    <select-box id="ad-version-select" options="curItem.stats.version" model="state.version" initial="All" change="watchvalue()" ng-disabled="state.partialDisable"></select-box>
</div>

<select class="form-control" ng-model="model" ng-change="change()">

    <option ng-if="initial.length" ng-bind="initial" value=""></option>
    <option ng-repeat="option in options" value="{{getValue()}}" ng-selected="model==getValue()" ng-bind="getTitleVariable()"></option>
</select>

I tried like

<style>
div.col-xs-3>div:first-child {
    font-weight: bold;
}
</style>

but didn't worked. I am not getting any idea how to make only the first value bold. I can't use jquery. Can someone help me with this?

1
  • not hard to see that css selector has nothing to do with <select> or <option> Commented Jan 19, 2016 at 4:25

3 Answers 3

1

There need to be an alteration done in your css selector. You should select the first child of the option to make it bold.

option:first-child
{
  font-weight: bold;  
}

Here is the sample Fiddle

Hope this helps.

-Help :)

Sign up to request clarification or add additional context in comments.

3 Comments

That was a general solution to the problem. If you can upload a Fiddle for your question then we can dig in it.
This code is having more of angular part and less javascript . I am new to all these and my attempts to set up fiddle with this code, failed.
Try to add a class to the select and in that class add that css.
0

You can use ng-options with ng-class:

<select ng-model="Blah">
  <option ng-repeat="person in persons" ng-class="{red: person.id == 1}" ng-selected="{Blah == person.Name}">{{person.Name}}</option>  
</select>

app.controller('AppController',
[
  '$scope',
  function($scope) {
    $scope.persons = [
      {id: 1, Name:'John',Eligible:true},
      {id: 2,Name:'Mark',Eligible:true},
      {id: 3,Name:'Sam',Eligible:false},
      {id: 4, Name:'Edward',Eligible:false},
      {id: 5, Name:'Michael',Eligible:true}
    ];

    $scope.Blah = 'Sam';

  }
]);

Here is the Plunker

2 Comments

What if the ID changes? Or the object structure? Really should use ng-repeats $index instead of doing this.
It's just an example. Of course you can use this ng-class="{red: $index == 0}"
0

@Help's solution should work. But not all browsers support styles in <select><option>. Maybe you need to build the component by yourself, something like this:

<div class="select">
  <div class="selected" ng-bind="current.title"></div>
  <div class="options">
    <div class="option" ng-repeat="option in options" value="{{option.value}}" ng-bind="option.title" ng-click="current=option"></div>
  </div>
</div>
.option:first-child {font-weight: bold;}

You'll need to add some more scripts and styles to make it work like a natural <select>.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.