我有一个父DIV width:100%和overflow:hidden
我需要放置的图像2500-3000px内,但具有水平居中的图像(裁剪左侧和右侧),以使图像的主要中心部分显示在小屏幕上,但没有水平滚动条.
我无法使用,background-image因为图像是通过PHP动态添加的.
请帮忙.
Ry-*_*Ry- 10
如果您事先知道图像的宽度和高度(即它们都是相同的),那么您可以使用旧margin/ position技巧:
#myImage {
height: the image's height;
left: 50%;
margin-left: -half the image's width;
margin-top: -half the image's height;
position: relative;
top: 50%;
width: the image's width;
}Run Code Online (Sandbox Code Playgroud)