繁体   English   中英

CSS 新手背景图供输入

[英]CSS newbie background image for input

我有一个包含多个图标的 16x16 数组的图像。 例如“http://www.freepbx.org/v3/browser/trunk/assets/css/jquery/vader/images/ui-icons_cd0a0a_256x240.png?rev=1”

知道如何仅选择其中一个图标并使用 CSS 将其设置为背景图像吗?

我想要实现的是在输入文本元素的右侧有一个 x 图标或刻度图标,以通知用户他作为输入提供的内容是有效还是无效。

谢谢,斯塔夫罗斯

您可以将元素的高度设置为所需图像中图标的高度,然后像这样设置该元素的背景:

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

其中使用的元素是跨度,所需的图标位于 position (50px, 10px)。 要了解有关定位背景的更多信息,请查看: http://www.w3schools.com/cssref/pr_background-position.asp

您可以使用 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