text-align: justify not working

Alex Pliutau picture Alex Pliutau · Dec 19, 2010 · Viewed 11k times · Source

HTML

<div id="menu">
    <a href="#">Commissions</a>
    <a href="#">Business Setup</a>
    <a href="#">Administrator</a>
    <a href="#">Content Management</a>
    <a href="#">Inventory</a>
    <a href="#">Communications Tools</a>
    <a href="#">Genealogy</a>
    <a href="#">Reports</a>
</div>

CSS

#menu {
    width: 1000px;
    float: left;
    font-size: 9pt;
    text-align: justify;
}
#menu a {
    text-decoration: none;
    color: #0066cc;
    font-size: 9pt;
}
#menu a:hover {
    text-decoration: underline;
}

I want to make each links to have the whole width. I tried to implement so with text-align: justify. But it's not working. How can I do this?

Answer

TorranceScott picture TorranceScott · Aug 6, 2013

This will make evenly spaced divs(can be links or about any element). The issue you ran in to is that justify doesn't work on a single line of text (or the last line of text). That is why you need the :after psuedo element.

Html:

<div class="wrapper">
  <div>This can be anything.</div>
  <div>This can be anything.</div>
  <div>This can be anything.</div>
  <div>This can be anything.</div>
  <div>This can be anything.</div>
  <div>This can be anything.</div>
</div>

Css:

.wrapper{
  text-align: justify;
}
.wrapper div{
  display: inline-block;
}
.wrapper:after{
  content: "";
  width: 100%;
  display: inline-block;
}