简体   繁体   English

CSS 新手背景图供输入

[英]CSS newbie background image for input

I have an image with and array 16x16 of multiple icons.我有一个包含多个图标的 16x16 数组的图像。 eg "http://www.freepbx.org/v3/browser/trunk/assets/css/jquery/vader/images/ui-icons_cd0a0a_256x240.png?rev=1"例如“http://www.freepbx.org/v3/browser/trunk/assets/css/jquery/vader/images/ui-icons_cd0a0a_256x240.png?rev=1”

Any idea how to choose only one of those icons and set it as a background image using CSS?知道如何仅选择其中一个图标并使用 CSS 将其设置为背景图像吗?

What I want to achieve is have an x icon or tick icon to the right of an input text element in to notify the user if what he has given as input is valid or invalid.我想要实现的是在输入文本元素的右侧有一个 x 图标或刻度图标,以通知用户他作为输入提供的内容是有效还是无效。

Thanks, Stavros谢谢,斯塔夫罗斯

You would set the height of an element to the height of the icon in that image that you want, and then set the background of that element like so:您可以将元素的高度设置为所需图像中图标的高度,然后像这样设置该元素的背景:

span {
    background:url(path/to/image) 50px 10px;
    height:10px;
    width:10px;
}

Where the element used is a span, and the desired icon is at position (50px, 10px).其中使用的元素是跨度,所需的图标位于 position (50px, 10px)。 To learn more about positioning backgrounds have a look at: http://www.w3schools.com/cssref/pr_background-position.asp要了解有关定位背景的更多信息,请查看: http://www.w3schools.com/cssref/pr_background-position.asp

You can accomplish this with css, something like this:您可以使用 css 完成此操作,如下所示:

div#myDiv {
    background-image:url('url-to-image');
    background-position:50px 50px; /* coordinates of the top left corner of the image portion you want to display */
    width:20px; /* Width of image portion */
    height:20px; /* Height of image portion */
}

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

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