Solved

Why do seem to be running out of room?

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

749 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