Css attribute to access a specific selectInput and make the initial element bold

感情迁移 提交于 2019-12-13 08:39:19

问题


the given html script creates three selectInputs and updates the first element of all the three selectInputs black and bold. I just want to make the change to the third selectInput Box and not the other two. Please help me with an appropriate css attribute to achieve this.

<!DOCTYPE html>
<html>
<body>
<style>
option:first-child{
font-weight:bold;
color:#000000;
}
</style>
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
</select>
<select>
<option value="a1">Volvo1</option>
<option value="a2">Saab1</option>
</select>
<select>
<option value="v1">Volvo2</option>
<option value="v2">Saab2</option>
</select>
</body>
</html>


回答1:


You can use nth-child in css to select particular select tag and make its first option as bold like u did.

select:nth-child(3) option:first-child{
font-weight:bold;
color:#000000;
}

see the codepen below

See this pen




回答2:


Give the third select a class.

<select class="third">
<option value="v1">Volvo2</option>
<option value="v2">Saab2</option>
</select>

edit css:

.third option:first-child{
font-weight:bold;
color:#000000;
}


来源:https://stackoverflow.com/questions/48514038/css-attribute-to-access-a-specific-selectinput-and-make-the-initial-element-bold

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!