How to centralise images with an absolute position?
This question already has an answer here:
Another option is by using CSS3 transform
:
img{
display:block;
position:absolute;
left:50%;
transform:translate(-50%,0);
}
Add vendor prefixes as needed.
This has also been mentioned in an answer under the question Center an image with CSS (horizontal and vertical).
See the fiddle
To centralize absolutely positioned items, use
left:0;
right:0;
along with margin:0 auto;
In addition to setting automatic margins and absolute positioning, you also need to set all the offsets (top/left/etc) to 0. This method should work as long as you have a declared height:
.absolute-center {
margin: auto;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
}
(source)
链接地址: http://www.djcxy.com/p/75762.html上一篇: 图像以div为中心
下一篇: 如何集中图像的绝对位置?