Solved

Fixed navigation <div> elements with other elements over top

Posted on 2013-05-17
6
317 Views
Last Modified: 2013-05-20
My test page:
http://sterlingmodular.com/test

Each of the colored bars running across the page is a <div> with position:fixed.

Now, I want to place the logo <img> and have it be overtop the colored bars, but it is behind (you can see part of it below the third bar). It comes after the bars in the markup, so I thought it would always be on top. The position:fixed changes that?

Is there some other way I can make the colored bars more of a background, so that I can put the logo overtop? Other than doing a position:absolute with the logo, set a z-index, etc.?

Basically, how do I keep those bars as position:fixed, but not have them affect other elements place overtop? They should be behind everything else.

Thank you!
0
Comment
Question by:bbdesign
  • 3
  • 2
6 Comments
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 39177250
This gets your answer http://jsbin.com/oduzoc/1/ but not really a good way of doing it.

<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Sterling Modular</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Michroma">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Alex+Brush">
<link rel="stylesheet" href="http://sterlingmodular.com/test/css/normalize.css">
<link rel="stylesheet" href="http://sterlingmodular.com/test/css/main.css">
<link rel="stylesheet" type="text/css" href="fhttp://sterlingmodular.com/test/loatbox/floatbox.css" />
<script src="http://sterlingmodular.com/test/floatbox/floatbox.js"></script>
<script src="http://sterlingmodular.com/test/js/vendor/modernizr-2.6.1.min.js"></script>
 <style>
 #logo {
	position: absolute;
	z-index: 99999;
	left: 0px;
	top: 0px;
}
 </style> 
</head>
<body>
  <div id="logo"><img src="http://sterlingmodular.com/test/img/lg_sterling-modular.jpg" alt="Sterling Modular" width="141" height="47" border="0" /></div>
<div id="nav1" class="redbar">

	<ul>
		<li><a href="">INTERNATIONAL SALES</a></li>
		<li><a href="">PRESS / REVIEWS</a></li>
		<li><a href="">ABOUT US</a></li>
		<li><a href="">DOWNLOADS</a></li>
		<li><a href="">CONTACT</a></li>
		<li><a href="">SHOPPING CART</a></li>
	</ul>
</div>

<div id="nav2" class="lightbar">
	<div id="tagline">Fine Studio Furniture from the Most Respected Name in the Industry</div>
</div>

<div id="nav3" class="darkbar">
	<ul>
		<li><a href="">U.S. RETAILERS</a></li>
		<li><a href="">ABOUT CONSOLES AND ACOUSTICS</a></li>
		<li><a href="">PHOTO GALLERY</a></li>
		<li><a href="">STERLING USERS</a></li>
	</ul>
</div>

<div id="wrapper">
	

	<p>Sample default font size and styling for Michroma.</p>

	<p class="cursive">Yes... You Have Arrived</p>

	<p><a class="btn">SAMPLE BUTTON</a></p>

	<p style="width:200px;height:100px;background-color:#9b1d30;text-align:center;">SAMPLE RED COLOR</p>
</div>

<div id="nav4" class="lightbar">
	<ul>
		<li><a href="">ACCESSORIES</a></li>
		<li><a href="">HIGH END MASTERING</a></li>
		<li><a href="">CUSTOM SHOP</a></li>
	</ul>
</div>

<script src="http://sterlingmodular.com/test/js/vendor/jquery-1.7.2.min.js"></script>
<script src="http://sterlingmodular.com/test/js/plugins.js"></script>
<script src="http://sterlingmodular.com/test/js/main.js"></script>

</body>
</html>

Open in new window

0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39177258
I would probably make your 3 top bars one image, a thin slice that repeats in the background of a header div.  Then use css to make the image on the top left (change to a transparent png) and float the logo div to the left and margin right.  Then you will have the nav text for the 3 levels to the right of the logo.

<div id="header">
     <div id="logo">myimage</div>
     <div id="three_navs">
           <div id="top_nav">stuff</div>
           <div id="mid_nav">stuff</div>
            <div id="bottom_nav">stuff</div>
     </div>
</div>

Open in new window

0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 39177424
If you want something to be fixed background, the turn it into an image and set it as the fixed background.  If you want it to be part of content, then learn to use css to do real layout instead of just plopping thing in a page using fixed and/or absolute positioning.

Cd&
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:bbdesign
ID: 39178497
My reasoning behind doing the separate <div> elements is because I may want to use those same backgrounds elsewhere in the website. I thought I would define them once, and reuse as necessary. Maybe I can put all three in a <div> and fix that <div>, instead of fixing each individual one?

Thanks for your input, I will go through this in more detail tomorrow.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39179307
If you want to use the same background in other parts of the site, just set it up as a sprit.  

Consider this when taking the extra steps to make a sprit; assume the think slice is 3k, viewed a 10,000 times is about 30 megs of bandwidth.  If you save 2k by using the sprite, that's 20 megs of bandwidth.     I think you would need to see a million page views before the bandwidth savings make a difference.
0
 

Author Comment

by:bbdesign
ID: 39182601
Thanks for your good advice. I'm still working on it, but I think I know what to do now.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
CSS: Why are my submenu options not 100% wide? 5 26
css, html 6 31
Problem to ToolkitScriptManager 2 32
Login area of a page 4 20
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now