Solved

Why do seem to be running out of room?

Posted on 2015-01-15
3
60 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTML and CSS for a complex page 20 63
CSS Font Arial Narrow 2 31
Why won't this text float to the left 8 26
Slider Moving to right hand side CSS? 2 9
"I want to put my photos online, but I don't want them stolen.  What settings should I use?" When You Put Photos Online First and foremost, any digital file published on the WWW can be copied, stored, modified, retransmitted, etc.  Remember Naps…
When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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…

862 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

25 Experts available now in Live!

Get 1:1 Help Now