调整 Windows 大小时徽标会到处移动
好吧,我正在开发的网站有问题。事实上,我经常遇到这个问题,但从未寻求帮助,我想现在是时候了。这是我的CSS:
header { background: #EEEEEE; height: 50px; } .logo { background: url(logo.png); width: 200px; height: 40px; margin: 0 280px; }
当我调整窗口大小时,标题中的徽标将在调整窗口大小时进入右侧。我尝试过绝对位置、相对位置等,但效果相同。请问大家有什么想法吗?
这是我的 HTML:
<header>
<div class="logo"></div>
</header>
这里是代表问题的图片的链接:
这是一切都完美运行的地方,一切都对齐了:
FullSizedWindow http://dl.dropbox.com/u/6212750/Full%20Sized%20Window.png
和
这个一切都开始变得混乱起来:
WhenWindowIsRished http: //dl.dropbox.com/u/6212750/When%20window%20is%20resized.png
有什么想法吗?请
Okay so I have a problem with a website I am working on.. infact I have this problem alot and never asked for help, I think it's time now. Here is my CSS:
header { background: #EEEEEE; height: 50px; } .logo { background: url(logo.png); width: 200px; height: 40px; margin: 0 280px; }
When I resize my window the logo in the Header will go in to the right when the window is resized. I have tried position absolute, relative etc but it does the same thing. Any ideas please guys?
Here is my HTML:
<header>
<div class="logo"></div>
</header>
Here are links to pictures representing the problem:
This is where everything is working perfectly everything is alligned:
FullSizedWindow http://dl.dropbox.com/u/6212750/Full%20Sized%20Window.png
and
This is where everything starts to go all over the place:
WhenWindowIsRised http://dl.dropbox.com/u/6212750/When%20window%20is%20resized.png
Any ideas? Please
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
设置标题元素的宽度。默认为
width: auto;
,它覆盖 100% 的浏览器窗口。因此,当您重新调整窗口的宽度时,标题元素的大小也会随着内容的移动而调整。更新 1
您使用边距将徽标放置在距浏览器窗口左侧 280 像素的位置,因此当您调整窗口宽度时,您的徽标也会移动 - 徽标被“推动” 。您想要做的是将所有内容包装在容器 div 中,并设置相对于该容器的边距间距,而不是相对于浏览器窗口。
HTML
CSS
小提琴:http://jsfiddle.net/alpacalips/ybe9d/2 /
Set a width on the header element. It's defaulting to
width: auto;
which is spanning 100% of the browser window. Thus, when you re-size the window's width, the header element is re-sized too moving the contents.Update 1
You're using a margin to position the logo 280px from the left side of the browser window, so when you resize the window's width, your logo is moving too- the logo is being 'pushed'. What you want to do is wrap everything in a container div and set your margin spacing relative to that, not the browser window.
HTML
CSS
fiddle: http://jsfiddle.net/alpacalips/ybe9d/2/
我唯一能想到的就是完全设置背景属性。
细分为:
你能发布一个 JSFiddle 以便我可以看到它发生吗?
The only thing I could think to try off the top of my head would be to fully set the background properties.
Broken down that is:
Can you post a JSFiddle so I can see it happen?