简体   繁体   English

更改ASP.NET下拉框的样式

[英]Changing the style of ASP.NET Dropdown box

I have a default ASP.NET Dropdown, and it is rendered with a select tag id of "Countries". 我有一个默认的ASP.NET Dropdown,它的选择标记ID为“Countries”。

I'd like the background of the drop-down to be transparent to match with the background of the page, and also like to keep make the default border disappear as well, so it blends well with the background. 我希望下拉列表的背景是透明的,以匹配页面的背景,并且还希望使默认边框也消失,因此它与背景很好地融合在一起。 The list items can have the white background. 列表项可以具有白色背景。 I have an image of a custom arrow that i'd like to use instead of the default one that is used to click on the drop-down. 我有一个我想使用的自定义箭头的图像,而不是用于单击下拉列表的默认箭头。

On hovering over the drop-down list items, I'd like the background of the item to be yellow, and the font color should always be black. 将鼠标悬停在下拉列表项上时,我希望项目的背景为黄色,字体颜色应始终为黑色。

I'd like to use CSS 2.1 as much as possible for this, but if it's too complex then I'm willing to use javscript or jquery. 我想尽可能多地使用CSS 2.1,但如果它过于复杂,那么我愿意使用javscript或jquery。

Below is the rendered markup, and some custom styles I've been trying to write. 下面是渲染的标记,以及我一直在尝试编写的一些自定义样式。 I also think some of the styles are overwritten by some default ones. 我还认为一些默认的样式会覆盖一些样式。 Any help to finish this styling would be greatly appreciated. 任何帮助完成这种造型将不胜感激。 Thanks 谢谢

<select name="ContriesDropdown" class="Select.SmallSelect" id="Countries" style="width: 100px; background-color: white;" onblur="try{FormUtils_ElementErrorReset(this);}catch(e){}" onchange="Send(this.value);">

<option value="1">Country1

<option value="2">Country2

*CustomCss*

#Countries {   position:absolute; display:inline; top:6px;}

#Countries {background-color:transparent; vertical-align: middle; color: #44586D; border: 0px transparent; display: inline;padding:2px;}

#Countries Option:hover { color:black; background-color:Yellow; }

The default ASP.Net controls are very limited when it comes to styling. 在样式方面,默认的ASP.Net控件非常有限。 You should try using external controls like the JQuery UI dropdown instead. 您应该尝试使用外部控件,例如JQuery UI下拉列表。

http://jqueryui.com/autocomplete/#combobox http://jqueryui.com/autocomplete/#combobox

Try This. 尝试这个。

select
    {
        -webkit-appearance: button;
        -webkit-border-radius: 2px;
        -webkit-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.1);
        -webkit-padding-end: 20px;
        -webkit-padding-start: 2px;
        -webkit-user-select: none;
        background-image: url(../images/select-arrow.png), -webkit-linear-    gradient(#FAFAFA, #F4F4F4 40%, #E5E5E5);
        background-position: center right;
        background-repeat: no-repeat;
        border: 1px solid #AAA;
        color: #555;
        font-size: 10pt;
        margin: 0;
        overflow: hidden;
        padding-top: 2px;
        padding-bottom: 2px;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-family: Cambria;
    }

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

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