调整 Windows 大小时徽标会到处移动

发布于 2024-12-29 08:08:34 字数 920 浏览 0 评论 0原文

好吧,我正在开发的网站有问题。事实上,我经常遇到这个问题,但从未寻求帮助,我想现在是时候了。这是我的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吲‖鸣 2025-01-05 08:08:34

设置标题元素的宽度。默认为 width: auto; ,它覆盖 100% 的浏览器窗口。因此,当您重新调整窗口的宽度时,标题元素的大小也会随着内容的移动而调整。

更新 1

您使用边距将徽标放置在距浏览器窗口左侧 280 像素的位置,因此当您调整窗口宽度时,您的徽标也会移动 - 徽标被“推动” 。您想要做的是将所有内容包装在容器 div 中,并设置相对于该容器的边距间距,而不是相对于浏览器窗口。

HTML

<div id="container">
    <header>

    <div class="logo"></div>

    </header>
</div>

CSS

#container {
    width: 400px;
    margin: 0 auto;
}
header {     
    background: #EEEEEE;    
} 
.logo {     
    background: url(http://i.imgur.com/4hs7p.png) no-repeat top left;    
    width: 200px;     
    height: 198px;     
    margin: 0;    
}

小提琴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

<div id="container">
    <header>

    <div class="logo"></div>

    </header>
</div>

CSS

#container {
    width: 400px;
    margin: 0 auto;
}
header {     
    background: #EEEEEE;    
} 
.logo {     
    background: url(http://i.imgur.com/4hs7p.png) no-repeat top left;    
    width: 200px;     
    height: 198px;     
    margin: 0;    
}

fiddle: http://jsfiddle.net/alpacalips/ybe9d/2/

日暮斜阳 2025-01-05 08:08:34

我唯一能想到的就是完全设置背景属性。

background: url(logo.png) 0 0 no-repeat;

细分为:

background: url [left,right,px,%] [top,bottom,px,%] [repeat];

你能发布一个 JSFiddle 以便我可以看到它发生吗?

The only thing I could think to try off the top of my head would be to fully set the background properties.

background: url(logo.png) 0 0 no-repeat;

Broken down that is:

background: url [left,right,px,%] [top,bottom,px,%] [repeat];

Can you post a JSFiddle so I can see it happen?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文