I want to add a background image on the right side of the list items, and want to have some padding from the right side as well, but I'm unable to do that. Please have a look at following example:
HTML:
<ul> <li>Hello</li> <li>Hello world</li> </ul>
CSS:
ul{ width:100px; } ul li{ border:1px solid orange; background: url("arrow1.gif") no-repeat center right; } ul li:hover{ background:yellow url("arrow1.gif") no-repeat center right; }
I know we can set the image position by pixels, but since each of the li has different width, I can't do that.
Here's JSFiddle link: http://jsfiddle.net/QeGAd/1/
The padding-box value means that the only the padding box part of the HTML element has the background image rendered. The content-box value means that the only the content box part of the HTML element has the background image rendered.
you can use background-origin:padding-box; and then add some padding where you want, for example: #logo {background-image: url(your/image. jpg); background-origin:padding-box; padding-left: 15%;} This way you attach the image to the div padding box that contains it so you can position it wherever you want.
Rather than leave the padding transparent, you can add color to the padding since the background color doesn't fully extend past the text element.
The background-origin is a property defined in CSS which helps in adjusting the background image of the webpage. This property is used to set the origin of the image in the background. By default, this property sets the background image origin to the upper-left corner of the screen/webpage.
You can be more precise with CSS background-origin:
background-origin: content-box;
This will make image respect the padding of the box.
You can use percent values:
background: yellow url("arrow1.gif") no-repeat 95% 50%;
Not pixel perfect, but…
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With