缩放时 Div 标签会移动
我对 HTML 还很陌生,我正在尝试使用一些 div 标签在放大或缩小页面时移动。我的 HTML 代码的结构是:
<header>
<div class="header">
<div class="title">
<h1>Here goes a title</h1>
</div>
<div class="logo">
<img class="logo" src="my/image/path.png">
</div>
</div>
</header>
相应的 CSS 代码:
header{
padding-left: 260px;
padding-top: 65px;
padding-right: 0px;
padding-bottom: 20px;
}
.title{
float: left;
width: 50%;
}
img.logo{
width: 243.77px;
height: 73.43px;
padding-top: 3px;
position: absolute;
}
缩放时我的标题和徽标图像都会移动。
任何帮助将不胜感激。
问候。
I am pretty new at HTML, and I am experimenting with some div tags to move along when zooming in or out the page. The structure of my HTML code is:
<header>
<div class="header">
<div class="title">
<h1>Here goes a title</h1>
</div>
<div class="logo">
<img class="logo" src="my/image/path.png">
</div>
</div>
</header>
And the corresponding CSS code:
header{
padding-left: 260px;
padding-top: 65px;
padding-right: 0px;
padding-bottom: 20px;
}
.title{
float: left;
width: 50%;
}
img.logo{
width: 243.77px;
height: 73.43px;
padding-top: 3px;
position: absolute;
}
Both my title and the logo image moves when zooming.
Any help would be appreciated.
Regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为您使用
padding-left
来更改整个标题的位置,而且您还使用px
单位,这使得它的位置在不同的屏幕尺寸下似乎不断变化。解决方案是改用百分比或使用媒体屏幕查询。
一个题外话的建议,使用
padding
来改变位置并不总是一个好的做法,使用margin
总是更好。*这是一个示例使用百分比,您可以根据需要进行更改。
That is because you use the
padding-left
to change the position of the full header, but also you use thepx
unit which makes its position seems keep changing in different screen size.A solution is to use percentage instead or use media screen query.
An off-topic suggestion, it is not always a good practice to use
padding
to change position, usemargin
is always better.*This is an example use percentage you could change based on what you want.