?
Solved

Why do seem to be running out of room?

Posted on 2015-01-15
3
Medium Priority
?
88 Views
Last Modified: 2015-01-15
Attached is a graphic that shows you my problem.

The grey area is my navcontainer:

.navcontainer {
margin:auto;
width:1300px;
height:29px;
position:relative;
z-index:6;
background-color:#cccccc;
}

Plenty of room to get all of my links in, which look like this:

a.home {
position:relative;
float:left;
margin-top:2px;
width:39px;
height:12px;
background-image:url(../images/button_home.png);
background-repeat:no-repeat;
}

a.regions {
position:relative;
float:left;
margin-top:2px;
margin-left:25px;
width:51px;
height:15px;
background-image:url(../images/button_regions.png);
background-repeat:no-repeat;
}

a.planning {
position:relative;
float:left;
margin-top:2px;
margin-left:25px;
width:58px;
height:15px;
background-image:url(../images/button_planning.png);
background-repeat:no-repeat;
}

a.budget {
position:relative;
float:left;
margin-top:2px;
margin-left:25px;
width:189px;
height:15px;
background-image:url(../images/button_budget.png);
background-repeat:no-repeat;
}

a.network_tools {
position:relative;
float:left;
margin-top:2px;
margin-left:25px;
width:181px;
height:15px;
background-image:url(../images/button_network_tools.png);
background-repeat:no-repeat;
}

a.network_ops {
position:relative;
float:left;
margin-top:2px;
margin-left:25px;
width:132px;
height:15px;
background-image:url(../images/button_network_ops.png);
background-repeat:no-repeat;
}

a.reference {
position:relative;
float:left;
margin-top:2px;
margin-left:25px;
width:66px;
height:12px;
background-image:url(../images/button_reference.png);
background-repeat:no-repeat;
}

a.reports {
position:relative;
float:left;
margin-top:2px;
margin-left:25px;
width:120px;
height:15px;
background-image:url(../images/button_reports.png);
background-repeat:no-repeat;
}

Open in new window


That's my CSS, here's my HTML:

	<div class="nav_bar">
				<div class="navcontainer">
				<a href="index.php" class="home"></a>
				<a href="index.php" class="regions"></a>
				<a href="index.php" class="planning"></a>
				<a href="index.php" class="budget"></a>
				<a href="index.php" class="network_tools"></a>
				<a href="index.php" class="network_ops"></a>
				<a href="index.php" class="reference"></a>
				<a href="index.php" class="reports"></a>
				</div>
			</div>

Open in new window


It was only after I got to my third link or so that I noticed that I needed to adjust the "margin-left" value to keep my links from sliding under one another, like what you see in the attached graphic.

I'm at the last link and the amount of adjusting I've done with the left margin now has things uncomfortably close to one another, yet it seems like I've got plenty of room.

Bottom line: I need to get all my links lined up horizontally and distributed evenly in my container. Things are getting crowded, apparently, yet I can't see how given the amount of room I seem to have.

What am I doing wrong?

Thanks!

screenshot
0
Comment
Question by:brucegust
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 2000 total points
ID: 40551842
The float is probably the source of the problem. <a is an inline element and it natural behavior is to float already.  when you stconfusing the rendering engine with floats and margins and positioning it looks like it gets a little flaky. try it without the float, or give the <a> elements a display: block; or a display inline-block,

But just allowing the natural flow should give you what you want.

Cd&
0
 

Author Comment

by:brucegust
ID: 40551847
You nailed it. I went back and postioned them as part of list and it worked great.

Thanks!
0
 
LVL 8

Expert Comment

by:albacom
ID: 40551918
Try the following code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<style type="text/css">
.nav_bar{
	/*float:left;*/	
	margin:0 auto;
	padding:5px; 
	/*width:100%;*/
	width:960px;
	height:70px;
	background:#06C;
}
.nav_bar .navcontainer{
	float:left;	
	margin:0;
	padding:5px 1%; 
	width:98%;
	height:60px;
	background:#0C6;
}
.nav_bar .navcontainer a{
	float:left;
	text-decoration:none;	
	margin:0 5px;
	padding:10px 5px; 
	/*width:10%; /*100% / 8(links) = 12.5% but we need to allow space/account for the margins
	and paddins as well. Adding background image link text is inefficient as you need to change the 
	size of containers and bg images in photoshop. You may also remove the width for the links container
	so the text and containers autofit */
	height:30px;
	font-size:1.2em;
	font-weight:bold;
	color:#C30;
	background:#CCC;
	border:#666 2px solid; 
}
.nav_bar .navcontainer a:hover{
	background:#FFF;
}



</style>

</head>

<body>

	<div class="nav_bar">
        <div class="navcontainer">
        <a href="index.php" class="home">Home</a>
        <a href="index.php" class="regions">Regions</a>
        <a href="index.php" class="planning">Planning</a>
        <a href="index.php" class="budget">Budget</a>
        <a href="index.php" class="network_tools">Network Tools</a>
        <a href="index.php" class="network_ops">Network Options</a>
        <a href="index.php" class="reference">Reference</a>
        <a href="index.php" class="reports">Reports</a>
        </div>
    </div>
            
</body>
</html>

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Suggested Courses
Course of the Month12 days, 2 hours left to enroll

752 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