开发者

Creating a simple header for website - why can't I get the img to float all the way right?

开发者 https://www.devze.com 2023-04-12 02:44 出处:网络
I am making a very simple blog for my PHP project, but am having a simple problem. I can\'t get the image for my header to float all the way right.

I am making a very simple blog for my PHP project, but am having a simple problem. I can't get the image for my header to float all the way right. I have a banner with some text on the left, I have a 1px slice repeating across the width of whatever resolution may be chosen (ensuring the banner fills any screen). I would like the image to always render on the right edge of the screen, again, independent of screen resolution. But it is coming in at a fixed position. Here is what I have written:

HTML:

<div id="header">
    <img src="images/banner.jpg" alt="banner" title="Prairie"/>
    <img class="right_image" src="images/banner_right_image.jpg" alt="elavator" title="prairie elevator"/>
</div>

CSS:

#header {
    position: fixed;
    top: 0px;
    width: 100%;
    height: 120px;
    background: u开发者_StackOverflow中文版rl(images/banner_right.jpg) repeat-x;
    z-index: 1;
}
#header.right_image {
    float: right;
    position: fixed;
    top: 0px;
    z-index: 1;
}

What is the issue here?

Thanks for any input.


You should separate #header.right_image so that it is #header .right_image

Also remove position: fixed from #header.right_image

This works:

#header .right_image {
    float: right;
}

Example: http://jsfiddle.net/FTBWU/


A link to your site would help!

I always throw at the top of my header:

 * { margin:0; padding:0}

You probably have padding or margins inherintly applied to your html or body tags depending on what browser you're using. Try that - and the is there a URL I can see the whole thing at?


I don't know how well the float works with a fixed positioned element. Maybe try something like this for your image?

#header .right_image {
    right: 0px;
    position: fixed;
    top: 0px;
    z-index: 1;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号