网站首页 > PHP源码 > 文件数据 > 我可以将CSS背景定位到“底部减去x像素”吗?

我可以将CSS背景定位到“底部减去x像素”吗?

  • 作者:互联网
  • 时间:2026-01-19 14:44:01
我需要将我的背景放在屏幕的底部.但在移动设备分辨率上,我希望将其显示为低于100px,例如“bottom minus 100px”.是否可以在CSS中实现这样的功能? 是的,使用background-position属性的四值语法.

介绍

// This two-value declarationbackground-position: center bottom// Is equivalent of this four-value declarationbackground-position: center 0px bottom 0px

免责声明:支持Chrome 25,Firefox 13,IE9,Safari 7

在你的情况下

因此,您可以将背景定位为“底部减去100px”:

background-position: center bottom -100px

例:

.container {  height: 190px;  padding: 1em;  margin: 0 auto 1em;  border: 1px solid #333;  text-align: center;    background-image: url('http://lorempixel.com/200/140/city/4');  background-repeat: no-repeat;  background-position: center bottom;}.plus {  background-position: center bottom 20px;}.minus {  background-position: center bottom -20px;}
background-position:
center bottom
background-position:
center bottom 20px
background-position:
center bottom -20px

见MDN documentation