背景图像位置(从底部和右侧)

时间:2014-12-30 05:37:52

标签: html css html5 css3 background

我需要像这样的背景定位: 从右侧50px,从底部60px 。如果我将背景位置放在右下角,它会向右下方移动。

这是html和css。



.box {
  background-image: url(http://www.iconbeast.com/images/iconbeast-pro.png);
  background-repeat: no-repeat;
  background-position: right bottom;
  height: 300px;
  width: 80%;
  border: 1px solid #AAA;
}

<div class="box">
  <p>
    This is a box. :) :)
  </p>
</div>
&#13;
&#13;
&#13;

我无法解决它,尽管我一直在尝试和搜索。谢谢:))

3 个答案:

答案 0 :(得分:1)

您可以使用calc(100% - 50px)(完整width - 50px)和calc(100% - 60px)(完整height - 60px)。

.box {
  background-image: url(http://www.iconbeast.com/images/iconbeast-pro.png);
  background-repeat: no-repeat;
  background-position: calc(100% - 50px) calc(100% - 60px);
  height: 300px;
  width: 80%;
  border: 1px solid #AAA;
}
<div class="box">
  <p>
    This is a box. :) :)
  </p>
</div>

答案 1 :(得分:0)

试试这个:

background-position: right 50px bottom 60px;

.box {
  background-image: url(http://www.iconbeast.com/images/iconbeast-pro.png);
  background-repeat: no-repeat;
  background-position: right 50px bottom 60px;
  height: 300px;
  width: 80%;
  border: 1px solid #AAA;
}
<div class="box">
  <p>
    This is a box. :) :)
  </p>
</div>

答案 2 :(得分:0)

更改背景位置

background-position: right 50px bottom 60px;
相关问题