我正在尝试创建带有图像的标题,但无论水平滚动如何,我都需要它保持居中。所以几乎保持它居中并随着滚动条移动,所以它总是显示。
我尝试将其居中并按照我在 SO 中找到的几个示例进行操作,但没有一个包含我需要的内容。
非常感谢任何帮助
最佳答案
听起来你想要固定位置:
img.centered
{
position: fixed;
top: 50%;
left: 50%;
margin-left: -100px; /* Width of image /2 */
margin-top: -100px; /* Height of image /2 */
}
HTML:
<body>
<img class="centered" src="..." />
</body>
关于javascript - 无论水平滚动如何,始终保持图像居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16795984/