图片相对于“square”的位置,在最右侧居中的位置。

.square{ width:100%;
height:500px;
position:relative;
}
img{ position:absolute;
z-index:2;
top:50%;
right:-2px;//不设置为0是为了避免出现图片的边框
margin-top:-10px;//将图片上移是为了能使其居中,根据图片的大小设置数值
}
本文介绍了一种方法,使得图片能在名为'square'的元素中最右侧居中显示。通过设置绝对定位和调整top及right属性,实现了图片的精确布局。
图片相对于“square”的位置,在最右侧居中的位置。

.square{ width:100%;
height:500px;
position:relative;
}
img{ position:absolute;
z-index:2;
top:50%;
right:-2px;//不设置为0是为了避免出现图片的边框
margin-top:-10px;//将图片上移是为了能使其居中,根据图片的大小设置数值
}
转载于:https://www.cnblogs.com/Thelma/p/5835973.html

被折叠的 条评论
为什么被折叠?