简体   繁体   English

HTML使用Sprite选择标签更改箭头

[英]Html select tag change arrow using sprite

I have a select tag that I would like to remove the arrow from and insert a different one for styling purposes; 我有一个选择标记,我想从中删除箭头,然后插入另一个标记来进行样式设置; however, the arrow I am inserting is in a sprite. 但是,我要插入的箭头是精灵。 I would like to keep it in the sprite if possible to minimize server requests. 我想尽可能将其保留在sprite中,以最大程度地减少服务器请求。 I only need to see the example in chrome, and then I can transpose it into the firefox and IE forms of the solution. 我只需要在chrome中查看示例,然后就可以将其转换为解决方案的Firefox和IE形式。 My attempt is in the JS Fiddle and the code is below. 我的尝试是在JS小提琴中 ,下面是代码。

HTML: HTML:

<select id="playerType">
    <option>Human</option>
    <option>Computer</option>
</select>

CSS: CSS:

#playerType {
    width: 81px;
    -webkit-appearance: none;
    background: url('http://goo.gl/8jNwT') no-repeat -250px -117px;
}

My problem is that I don't know how to clip off the othre parts of the sprite other than the downwards chevron that I inserted. 我的问题是,除了插入的向下V形之外,我不知道该如何剪裁精灵的其他部分。 Any help would be much appreciated. 任何帮助将非常感激。

I would recommend to use a vertical sprite instead of a horizontal one. 我建议使用垂直精灵而不是水平精灵。

Also, each image in the vertical sprite should have at least the height of the select element. 同样,垂直精灵中的每个图像都应至少具有选择元素的高度。 (In Your example they have). (在您的示例中,他们拥有)。

Then you can use the vertical sprite right aligned. 然后,您可以使用垂直对齐的精灵。

Also, if you have other images in your sprite, not related to the dropdown, the image parts intended for the dropdowns should be as wide as your widest select element, the remainder of the space being filled with transparent, or whatever colour you wish to use. 另外,如果子画面中还有其他与下拉菜单无关的图像,则用于下拉菜单的图像部分应与最宽的选择元素一样宽,其余空间将被透明填充,或者您希望使用任何颜色采用。 (it needs a little guessing/anticipating) (需要一些猜测/期待)

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

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