本文介绍了使用px值相对于右下角定位背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要将 background-image 放在距离右侧和底部一定距离。

我不想使用 right borrom ,因为它会将它放在角落,%或距离左上角防止我的设计响应。 >
有一个CSS解决方案吗?

I wan to position the background-image in a certain distance from right and bottom.
I don't want to use right borrom since it will position it in the corner, and % or distance from left top prevent my design from being responsive.
is there a CSS solution for that?

推荐答案

是的,你可以尝试这样用 calc

Yes you could try something like this with calc.

.wrapper {
  background-image: url(http://www.bcebhagalpur.ac.in/images/Facebook.png);
  background-repeat: no-repeat;
  background-position: calc(100% - 40px) calc(100% - 40px);
  height: 300px;
  width: 50%;
  background-color: #DDD;
}
<div class="wrapper">
  <p>Lorem Ipsum Dolor set amet etc etc etc etc .....</p>
</div>

或者你可以只用4边定位:

Or you could do it with just 4 sides positioning:

.wrapper {
  background-image: url(http://www.bcebhagalpur.ac.in/images/Facebook.png);
  background-repeat: no-repeat;
  background-position: right 40px bottom 40px;
  height: 300px;
  width: 50%;
  background-color: #DDD;
}
<div class="wrapper">
  <p>Lorem Ipsum Dolor set amet etc etc etc etc .....</p>
</div>

这篇关于使用px值相对于右下角定位背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 20:20