页面无意中扩展
我最近一直在为自己开发一个网站,遇到了一个奇怪的问题。每当我将 a 向左移动时,页面就会扩展我从中心向左移动的像素数。它不会妨碍功能,但拥有可以滚动到一侧的 300-400 像素空间确实很烦人。也许我做错了什么,但任何帮助将不胜感激。
这是我正在做的事情的一个例子:
<html>
<body style="background-image: url('Background-Large.jpg'); text-align: center">
<div style="position:relative;top: -605px; left: 295px;"></div>
</body>
</html>
I have been working on a website for my self recently and ran into an odd problem. Whenever I would move a to the left the page would expand by the amount of pixels I had moved it left from the center. It doesn't hinder functionality but it's really annoying to have this 300-400 pixel space that you can scroll off to the side with. Maybe I'm doing something wrong but any help would be appreciated.
This is an example of what I am doing:
<html>
<body style="background-image: url('Background-Large.jpg'); text-align: center">
<div style="position:relative;top: -605px; left: 295px;"></div>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不太确定你想在这里实现什么,但如果你在正文上放置“overflow:hidden”,它应该允许你将 div 定位在页面之外,而无需添加滚动条。
I'm not quite sure what you're trying to achieve here but if you put an 'overflow:hidden' on the body, it should allow you to position your div off the page without adding a scroll bar.
这是因为您的 DIV 已设置:
如果您希望 DIV 位于中心,您应该做的第一件事是创建一个“主容器”:
然后从那里您可以在现在居中的容器内添加元素:
It's because your DIV is set:
If you want a DIV to be in the center the first thing you should do is make a "main container":
Then from there you can add elements inside that container thats now centered: