Reputation: 89
I have 6 links, all different character lengths on two lines. I need everything to align evenly. Like this:
Home About Us Location
Contact Visit Schedule
I imagine the way to do this is to make the li
a specific width and then apply an appropriate margin to the right side, but for some reason I can't apply a width. If I have the following html skeleton, how would I edit the CSS to accomplish this? I've looked around the web for a solution, but I've haven't found any similar questions because my menu sits on two separate lines.
<div class="footer">
<ul id="footerlinks">
<li><a href="link 1">Home</a></li>
<li><a href="link 2">About Us </a></li>
<li><a href="link 3">Location</a></li>
<br>
<li><a href="link4">Contact</a></li>
<li><a href="link5">Visit</a></li>
<li><a href="link6">Schedule</a></li>
</ul>
Upvotes: 0
Views: 8413
Reputation: 78971
Fix the width of <ul>
and <li>
. And remove the <br />
it makes the markup invalid.
HTML
<ul id="footerlinks">
<li><a href="link 1">Home</a></li>
<li><a href="link 2">About Us </a></li>
<li><a href="link 3">Location</a></li>
<li><a href="link4">Contact</a></li>
<li><a href="link5">Visit</a></li>
<li><a href="link6">Schedule</a></li>
</ul>
CSS
#footerlinks { width: 300px; }
#footerlinks li { width: 100px; display: inline-block; }
Upvotes: 1
Reputation: 1575
First, a <br/>
is not a valid child element of <ul/>
.
To apply a width to an <li/>
, you will need to make it a block-level element.
<ul id="footerlinks">
<li><a href="link 1">Home</a></li>
<li><a href="link 2">About Us </a></li>
<li><a href="link 3">Location</a></li>
<li><a href="link4">Contact</a></li>
<li><a href="link5">Visit</a></li>
<li><a href="link6">Schedule</a></li>
</ul>
and
#footerlinks {
background:#ccc;
overflow:hidden;
padding:5px;
width:300px;
}
#footerlinks li {
float:left;
padding:5px 0;
width:33%;
}
Here is a working example - http://jsfiddle.net/jaredhoyt/xbvyP/
Upvotes: 0
Reputation: 7367
Check this:
<pre>
test
	test
		test
</pre>
Source: How do I create tab indenting in html
Upvotes: 0