Solved

Why do seem to be running out of room?

Posted on 2015-01-15
3
80 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 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

CSS3 Custom checkboxes This article shows how to style the checkbox form element using only CSS. Works in: Chrome, FF, Safari, Opera, IE9+ Uses modernizr.js to check for :checked pseudo class, falling back to plain old checkboxes (IE8 and bel…
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
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…

724 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