Html 在顶部固定图像,但在侧面具有自动边距
我有以下html:Html 在顶部固定图像,但在侧面具有自动边距,html,css,Html,Css,我有以下html: <div class="fix-to-top"> <div class="background-image"></div> </div> 然而,侧边距并不是“自动”的。我如何正确地做到这一点 img { position: fixed; right: 50%; width: 100px; height: 100px; margin-top: -50px; margin-r
<div class="fix-to-top">
<div class="background-image"></div>
</div>
然而,侧边距并不是“自动”的。我如何正确地做到这一点
img {
position: fixed;
right: 50%;
width: 100px;
height: 100px;
margin-top: -50px;
margin-right: -50px;
background: orange;
top: 50%;
}
检查此项
不需要使用两个div
您可以使用和属性来实现它这实际上并不能将其固定到顶部。如果更改浏览器窗口的大小,它将垂直“浮动”。我需要始终保持在顶部。对我来说,无论滚动,它都会粘在浏览器右侧的中间,这不是你想要的吗?嘿,我。也许这就是你想要的。
img {
position: fixed;
right: 50%;
width: 100px;
height: 100px;
margin-top: -50px;
margin-right: -50px;
background: orange;
top: 50%;
}