先科普一下背景图片的定位:http://www.php100.com/html/webkaifa/DIV_CSS/2009/0315/2440.html

所以background的居中代码就是:background:url(tu.png) no-repeat center center; 

有的时候会遇到必须要用img的居中,比如很多地方是要靠js来读取地址哒,所以不能用background。

代码如下:

关于img的图片居中问题,效果类似于background-position

这时候我们需要为img设置个外容器,上图的外容器就是body啦。img就相对于外容器body来进行位置的移动。所以就可以自适应各种屏幕,而居中啦。

 

相关文章:

  • 2022-01-08
  • 2021-10-03
  • 2018-11-02
  • 2021-09-17
  • 2021-08-27
  • 2021-10-14
  • 2021-10-14
  • 2021-11-21
猜你喜欢
  • 2021-12-29
  • 2021-09-14
  • 2021-08-29
  • 2021-12-05
  • 2022-01-01
  • 2021-11-14
  • 2021-10-20
  • 2021-12-03
相关资源
相似解决方案