简体   繁体   English

CSS中的下拉背景

[英]Drop-Down Background in CSS

I want to change the drop-down part of the drop-down menu same as the background color of the option part. 我想更改下拉菜单的下拉部分,使其与选项部分的背景颜色相同。

在此处输入图片说明

Added Snippet. 添加了代码段。

 .selectdropdown{ background: none repeat scroll 0 0 lightgreen; border: 1px solid rgba(0, 0, 0, 0.17); border-radius: 2px; box-shadow: 0 -2px rgba(0, 0, 0, 0.03) inset; color: #000000; cursor: pointer; display: inline-block; font-size: 12px; font-weight: normal; height: 30px; line-height: 28px; padding: 0 10px; position: relative; vertical-align: middle; white-space: nowrap; } 
 <select class="selectdropdown" name="Status"> <option value="Open">Open</option> <option value="Close">Close</option> <option value="Resolved">Resolved</option> <option value="On Hold">On Hold</option> </select> 

I assume you refer only on firefox cause in chorme looks ok. 我假设您仅在firefox上引用,因为在chorme中看起来还可以。 I suggest to hide default arrow and create a custom one: 我建议隐藏默认箭头并创建一个自定义箭头:

 .selectdropdown { background: none repeat scroll 0 0 lightgreen; border: 1px solid rgba(0, 0, 0, 0.17); border-radius: 2px; box-shadow: 0 -2px rgba(0, 0, 0, 0.03) inset; color: #000000; cursor: pointer; display: inline-block; font-size: 12px; font-weight: normal; height: 30px; line-height: 28px; padding: 0 10px; position: relative; vertical-align: middle; white-space: nowrap; appearance: none; -moz-appearance: none; /* Firefox */ -webkit-appearance: none; /* Safari and Chrome */ } .styled-select:after { content: ""; width: 0px; height: 0px; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 5px solid rgb(0, 0, 0); position: absolute; left: 64px; top: 21px; } 
 <div class="styled-select"> <select class="selectdropdown" name="Status"> <option value="Open">Open</option> <option value="Close">Close</option> <option value="Resolved">Resolved</option> <option value="On Hold">On Hold</option> </select> </div> 

Short answer: nope... 简短答案:不...

Long answer: depends on the browser and os you are using. 长答案:取决于您使用的浏览器和操作系统。 Form controls (checkboxes, selects, etc.) can be partially styled, and in most cases stuff like the carrot cannot. 表单控件(复选框,选择框等)可以部分设置样式,在大多数情况下,像胡萝卜这样的东西不能。 It can be quite frustrating, but it is what it is. 这可能很令人沮丧,但事实就是如此。

There are a few workarounds though. 不过,有一些解决方法。 First of all you can use bootstrap . 首先,您可以使用bootstrap They've done a pretty good job in styling form controls as flexible as possible and as cross-browser-proof as possible. 他们在样式表单控件方面做得很好,表单控件尽可能灵活,并且尽可能地跨浏览器保护。 However, it'll still look a bit different on different browsers and even on different os'es. 但是,在不同的浏览器,甚至在不同的操作系统上,它看起来仍然有些不同。

If that's not enough for you, you can use some javascript plugin which will produce (most of the times) an <ul> or any other container which will serve as a dropdown. 如果这还不够,您可以使用一些javascript插件(大多数情况下会产生<ul>或任何其他可以用作下拉菜单的容器。 In example bootstrap has done it , but you'll need a few lines of JS to get it to work as a select box. 在示例bootstrap 中,它已经完成了 ,但是您需要几行JS才能使其作为选择框工作。 But our friend google has tons of alternatives for the taking. 但是我们的朋友谷歌有很多可供选择的选择。

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

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