【发布时间】:2015-08-10 20:44:34
【问题描述】:
我正在使用 CSS3 background-position 将背景图像定位在距容器右边缘 3% 的位置。但是,与我有一个 97% 宽且背景图像右对齐的等效容器相比,它出现在不同的位置。您可以在http://jsfiddle.net/deshg/9qveqdcu/2/ 看到我的意思,黑色行中的徽标比绿色行中的徽标更靠右,但它们肯定应该处于相同的水平位置吗?
如果有人能解释为什么会发生这种情况,我们将不胜感激。
供参考,代码如下。
谢谢大家!
#container {
width: 100%;
background-color: #ffcc00;
}
#d1 {
background-color: #cccc00;
background-image: url('http://jsfiddle.net/img/logo.png');
background-position: right 3% center;
background-repeat: no-repeat;
width: 100%;
}
#d2 {
background-color: #000000;
color: #ffffff;
background-image: url('http://jsfiddle.net/img/logo.png');
background-position: right center;
background-repeat: no-repeat;
width: 97%;
margin-right: 3%;
}
<div id="container">
<div id="d1">
abvc
</div>
<div id="d2">
def
</div>
</div>
【问题讨论】:
-
好问题,好像有 1% 的折扣
标签: html css background-image background-position