简体   繁体   English

背景位置

[英]background-position

Im trying to use an image in textbox like so (## being the image): 我试图像这样在文本框中使用图像(##是图像):

 ---------------------
|                  ## |
 ---------------------

I have managed to somewhat with the following: 我设法做到以下几点:

input.loading {
    background: url(/images/loader.gif) no-repeat right;
}

However it comes out like so: 但是结果如下:

 ---------------------
|                   ##|
 ---------------------

What I need to do is add some padding to the right side but I am lost as to how I can accomplish this. 我需要做的是在右侧添加一些填充,但是我不知道如何实现此目的。

you could use a margin-right:10px; 您可以使用margin-right:10px; in your css 在你的CSS

Use this instead. 改用它。 It will solve your problem. 它将解决您的问题。

background-position:10px 200px;

See this example and play around :) 看这个例子,然后玩:)

You can change right to 98% or so. 您可以将right更改为98%左右。 ( right is just short hand for 100% ) right只是100%简写)

http://jsfiddle.net/gsUBL/ http://jsfiddle.net/gsUBL/

EDIT: I don't know why jsfiddle is having an issue with displaying it (in chrome at least). 编辑:我不知道为什么jsfiddle在显示它时有问题(至少在chrome中)。 Clicking run shows it working. 单击运行显示其正常工作。

I would change the positioning of no-repeat right; 我将更改no-repeat right;的定位no-repeat right; to a percentage that you want as right is just an easier way to to mark fully to the right or 100% . 达到您希望right的百分比只是一种更简单的方法,可以完全正确地标记到右侧或100% Positioning by pixels might cause unwanted horizontal scroll bars or even overlapping if their computers have a different display resolution. 如果像素的计算机的显示分辨率不同,则按像素定位可能会导致不需要的水平滚动条,甚至重叠。

There are multiple ways. 有多种方法。 If the input box is never going to change width then put the exact pixel amount you want in the CSS instead of "right" background: url(/images/loader.gif) no-repeat 200px; 如果输入框永远不会改变宽度,则在CSS中放入所需的确切像素数量,而不是“正确的” background: url(/images/loader.gif) no-repeat 200px; . I'd recommend rather doing exactly what you're doing background: url(/images/loader.gif) no-repeat right; 我建议您确切地做您正在做的background: url(/images/loader.gif) no-repeat right; and instead adding padding-right: 20px; 而是添加padding-right: 20px; (or however much you need) to the input box. (或您需要的数量)到输入框。

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

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