html中的绝对定位偏移问题处理

来源:互联网 发布:hpm226dn设置网络打印 编辑:程序博客网 时间:2024/05/22 16:42

html中的绝对定位偏移问题处理


      问题图:

     


  问题原因:

  img元素作为绝对元素,相对于外层div定位,未设置定义位置,

 会偏移相对元素的位置。

 

  问题代码:

 

#wrap .pic{    width: 100%;    height: 100%;    position: relative;    cursor: pointer;}#wrap .pic img{    position:absolute;      width: 100%;    height: 100%;}


   


  解决方法:

  设置相对元素的top、left、right、buttom

  确定相对元素的定位位置。


 实现代码:

 

#wrap .pic{    width: 100%;    height: 100%;    position: relative;    cursor: pointer;}#wrap .pic img{    position:absolute;    top: 0;    left: 0;    width: 100%;    height: 100%;}


  实现效果图:



原创粉丝点击