簡體   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