Solved

Why do seem to be running out of room?

Posted on 2015-01-15
3
56 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
3 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

762 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

12 Experts available now in Live!

Get 1:1 Help Now