Solved

Fixed navigation <div> elements with other elements over top

Posted on 2013-05-17
6
321 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating a CSS block that only applies to printing By default, all of your CSS applies to every possible view of your page - whether on screen, printed, landscape, touch-screen, or whatever.  You can, however, add CSS that only applies under certai…
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
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…

776 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