我想给一个div添加一个背景,位置在右中间,但是!,对图片进行一些填充.div为文本添加了填充,所以我想将背景缩进一点.可能最有意义,例如:
http://jsbin.com/umuvud/edit#javascript,html,live
谢谢
我想给一个div添加一个背景,位置在右中间,但是!,对图片进行一些填充.div为文本添加了填充,所以我想将背景缩进一点.可能最有意义,例如:
http://jsbin.com/umuvud/edit#javascript,html,live
谢谢
有人多次 comments 说,这不是这个问题的正确答案,我同意这一点.回到写这个答案的时候,IE9还很新(大约8个月大),包括我在内的许多开发人员都需要一个解决方案来解决<;=IE9.IE9就是IEstarted supporting background-origin
.然而,这已经超过六年半了,所以这里是我强烈推荐的更新的解决方案,而不是使用实际的边框.以防需要<;IE 9支持.我最初的答案可以在演示片段下面找到.它使用不透明边框来模拟背景图像的填充.
#hello {
padding-right: 10px;
background-color:green;
background: url("https://placehold.it/15/5C5/FFF") no-repeat scroll right center #e8e8e8;
background-origin: content-box;
}
<p id="hello">I want the background icon to have padding to it too!I want the background icon twant the background icon to have padding to it too!I want the background icon to have padding to it too!I want the background icon to have padding to it too!</p>
你可以用与背景 colored颜色 相同的10px边框来伪装它:
http://jsbin.com/eparad/edit#javascript,html,live
#hello {
border: 10px solid #e8e8e8;
background-color: green;
background: url("http://www.costascuisine.com/images/buttons/collapseIcon.gif")
no-repeat scroll right center #e8e8e8;
}