Customizing “Prosumer 1.4″ made by Nurudin Jauhari: Creating a Fluid Header using CSS
This post is in response to Nakul’s question on how to extend the header according to the browser’s width.
Here’s the challenge I gave myself: I want to make my Header stretch it’s background IF the browser width is more than the original width of the header (browser width > header’s width which is 950 px) and I want it to stay at 950 px if the browser’s width is less than 950 px.
So here’s how to do it.
1. Look for this code in your header.php file:
<div id=”top”>
<div id=”topi”></div>
<div id=”headr”>
<h1><a href=”<?php echo get_option(’home’); ?>/”>
<?php bloginfo(’name’); ?>
</a></h1>
<div class=”description”>
<?php bloginfo(’description’); ?>
</div>
<div class=”rss2″>
<a href=”<?php bloginfo(’rss2_url’); ?>” rel=”alternate” type=”application/rss+xml”><img src=”<?php bloginfo(’template_directory’); ?>/images/subscribe1.jpg” alt=”Subscribe” style=”border:0″/></a>
</div>
</div>
</div>
2. Add <div id=”pretop”> before the <div id=”top”>:
<div id=”pretop”>
<div id=”top”> <div id=”topi”></div> <div id=”headr”> <h1><a href=”<?php echo get_option(’home’); ?>/”> <?php bloginfo(’name’); ?> </a></h1> <div class=”description”> <?php bloginfo(’description’); ?> </div> <div class=”rss2″> <a href=”<?php bloginfo(’rss2_url’); ?>” rel=”alternate” type=”application/rss+xml”><img src=”<?php bloginfo(’template_directory’); ?>/images/subscribe1.jpg” alt=”Subscribe” style=”border:0″/></a> </div> </div> </div>
</div>
3. Open style.css and add this css style:
#pretop {
background-color: #161616; }
4. Upload the files to the remote server.
So there. we just added a fluid background on our header.
The pretop div that we added doesn’t contain any fix width so the width is browser dependent. Since it contains top div inside it which has a fix width of 950px, it will stop from shrinking once the browser’s width is less than 950 px.
HTH!
sid
how bad do you want change






May 8th, 2008 at 6:37 pm
Hey Sid, I tried this but its not working. I must be missing something.
Is there a particular place where I need to add the #pretop {
background-color: #161616; } in the style.css?
I have added it to the bottom of the sheet:
color: #A73228;
padding: 2px;
}
#pretop {
background-color: #161616; }
/* Change Log ***
May 9th, 2008 at 11:45 pm
@nakul - You can add the #pretop anywhere in the style.css. I added it at the bottom after this comment /*——- my addition ———-*/ .
did you add this code in header.php?
/”>
< ?php bloginfo(’name’); ?>
May 20th, 2008 at 12:35 pm
Hi - Can you repeat that code again please? I can’t read the text in your previous reply.
Thanks