简体   繁体   English

如何使用CSS将更改应用于“选择”选项

[英]How to apply changes to “select” option using CSS

Here's a sample of what it should look like : Select box image 这是它的外观示例: 选择框图像

I get country names from a database and generate dynamic options on page. 我从数据库中获取国家/地区名称,并在页面上生成动态选项。 Right now, i am showing the Html code (Not the database code). 现在,我正在显示HTML代码(不是数据库代码)。 I tried lots of links to change the design (CSS), but none of them work on "select". 我尝试了许多链接来更改设计(CSS),但是没有一个在“选择”上起作用。 I want to be able to change padding , border, background-color, color or border-color . 我希望能够更改padding , border, background-color, colorborder-color Can i apply modifications to all those, for "select", using css or not ? 我是否可以使用css对所有这些进行修改,以进行“选择”?

I also want to only show the first 5 options (first 5 country names) in the dropdown list when the button is clicked, using a scrollbar . 我也只想使用scrollbar在单击按钮时在下拉列表中显示前5个选项(前5个国家/地区名称)。

 #country option:first-child { display: none; } #country { float: left; width: 96%; color: #fff; font-size: 1em; font-family: "Calibri"; margin-left: 5px; padding: 8px 0px; margin-top: 16px; border: 1px solid #00BCEA; padding: 9px 5px; width: 93%; border-radius: 4px; color: #00BCEA; } 
 <select id="country"> <option value="selectOption">Select your country</option> <option value="selectOption1">Select your country1</option> <option value="selectOption2">Select your country2</option> <option value="selectOption3">Select your country3</option> <option value="selectOption4">Select your country4</option> <option value="selectOption5">Select your country5</option> <option value="selectOption6">Select your country6</option> <option value="selectOption7">Select your country7</option> </select> 

You can try the below plugins. 您可以尝试以下插件。 This will help you with styling your select box. 这将帮助您设置选择框的样式。 The select plugins map the select element into HTML <ul> element and apply the styles on them. select插件将select元素映射到HTML <ul>元素,并在其上应用样式。 If you inspect the DOM the select element would be visible, but hidden from the browser. 如果检查DOM,则select元素将可见,但对浏览器而言是隐藏的。

Hope this will help you 希望这个能对您有所帮助

Thanks, 谢谢,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM