0

I have a fixed header on my page, inside the header is an image. Id like it to stay in place when the window is resized.

I have tried different positioning tags and wrapper divs, but i must not be doing something right.

My CSS is as follows

.header {
    background: url("#") repeat-x scroll left top transparent;
    height: 70px;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
}

#headbar {
   position:fixed;
   z-index: 99999;
   left:0px;
   top:0px;
   height:50px;
   width:100%;
   background:#273D90;
   padding-top: 10px;
   box-shadow: 0 0 50px 0;
}

#headbar img {
    display: block;
    text-indent: -9999px;
    left: 5%;
    overflow: hidden;
    /*margin: 0 0 0 5%;*/
    position: fixed;
    float: left;
}

.imgwrap{
    float: left;
    position: absolute;
}

#logo {
    float: left;
    margin-right: 50px;
    margin-top:25px;        
}

and my HTML is

<div class="header">
    <div id="headbar">
        <div class="imgwrap">
            <a href="index.html"><img alt="logo" src="images/whitelogo.png" height="50" width="100"></a>
        </div>
    </div>  
</div>
4

2 回答 2

1

您的标题是100%页面的宽度。您的图像位于left: 5%. 那是5%标题的宽度。由于标题在窗口发生时调整大小,因此这5%会发生变化。使用px或使用固定值em,它不会移动。

http://jsfiddle.net/vfvxE/

于 2013-06-17T18:15:16.337 回答
0
#headbar img {
    display: block;
    text-indent: -9999px;
    left: 5%; /*  <--  % is relative */
    overflow: hidden;
    /*margin: 0 0 0 5%;*/
    position: fixed;
    float: left;
}

你将不得不使用亲属单位来实现你想要的。尝试使用绝对长度单位:'cm'、'mm'、'in'、'pt'、'pc'、'px' 单位

于 2013-06-17T18:14:48.317 回答