HTML:在屏幕的中间和右侧之间放置一个图像
我试着把一个图像放在屏幕中间和右边的中间位置(就是现在的位置) HTML代码:HTML:在屏幕的中间和右侧之间放置一个图像,html,Html,我试着把一个图像放在屏幕中间和右边的中间位置(就是现在的位置) HTML代码: <img src="jeremy.png" alt="Jeremy Smith" width="100" height="100" style="float:right"> 有没有办法将图像向右浮动3/4?或者类似的东西?最明显的方法是使用: #imgAtThreeQuarters { /* positioning the element in relation to its clo
<img src="jeremy.png" alt="Jeremy Smith" width="100" height="100" style="float:right">
有没有办法将图像向右浮动3/4?或者类似的东西?最明显的方法是使用:
#imgAtThreeQuarters {
/* positioning the element in relation to
its closest offset-parent element: */
position: absolute;
/* positioning the left-border of the
image 75% from the left-most border
of its closest offset-parent element: */
left: 75%;
/* moving the image to the left by half
of its width, to position the horizontal
center of the image at 75% of the
offset-parent's width: */
margin-left: -50px;
}
#四分之三{
位置:绝对位置;
左:75%;
左边距:-50px;
}
有很多方法可以实现这一点。我想到的一个简单方法是使用div将其对齐到屏幕的正确区域。您还可以将图像定位为绝对或将边距应用于图像
div {
margin-left: 50%;
text-align: center;
}
<div><img src="jeremy.png"><\div>
div{
左边距:50%;
文本对齐:居中;
}
边距和翻译是你最好的定位朋友。因为translate是自参考的,所以使用
transform:translate(-50%,0)
会使边距偏离图像的中心,而不是左边缘。这应该可以做到您可以使用一个右边距将其从右侧拉开…顺便说一句:float:right使元素浮动到其他元素的右侧。这不是一个对齐的事情,对不起,在上面的收尾部分输入了错别字(对不起,我在打电话)。不停摆弄
img {
width: 100px;
height: 100px;
margin-left: 75%;
transform: translate(-50%, 0);
}