2

There is something wrong with my code. I need to vertically center the text in the middle of each box.

#navcontainer {
    padding: 0 5 20px 10px;
}
ul#navlist {
    font-family: sans-serif;
}
ul#navlist a {
    font-weight: bold;
    text-decoration: none;
    display: inline-block;
    line-height:20px vertical-align: middle;
}
ul#navlist, ul#navlist ul, ul#navlist li {
    margin: 0 8px;
    padding: 0px;
    list-style-type: none;
    box-shadow: 8px 8px 12px #aaa;
}
ul#navlist li {
    float: left;
}
ul#navlist li a {
    color: #ffffff;
    background-color: #EF634A;
    //padding:10px;
    padding: 10px 5px 10px 5px;
    border: 1px #ffffff outset;
    height: 40px;
}
ul#navlist li a:hover {
    color: #ffff00;
    background-color: #003366;
}
ul#navlist li a:active {
    color: #cccccc;
    background-color: #003366;
    border: 1px #ffffff inset;
}
ul#subnavlist {
    display: none;
}
ul#subnavlist li {
    float: none;
}
ul#subnavlist li a {
    padding: 0px;
    margin: 0px;
    height: 20px;
}
ul#navlist li:hover ul#subnavlist {
    display: block;
    //display: inline-block;
    //display: table-cell;
    position: absolute;
    font-size: 8pt;
    padding-top: 5px;
}
ul#navlist li:hover ul#subnavlist li a {
    display: block;
    width : 260;
    height : 100;
    border: none;
    padding: 2px;
}
ul#navlist li:hover ul#subnavlist li a:before {
    content:" >> ";
}

and

<div id="navcontainer">
    <ul id="navlist">
        <li><a href="obs-geostrategique-sport.php?cat=1">PROGRAMME EUROPÉEN DE LUTTE <br/>CONTRE LE TRUCAGE DE MATCHS</a>
        </li>
        <li><a href="obs-geostrategique-sport.php?cat=2">ACTUALITÉS SPORTIVES</a>
        </li>
        <li><a href="obs-geostrategique-sport.php?cat=3">COMMUNIQUÉS</a>
        </li>
        <li id="active"><a href="obs-geostrategique-sport.php?cat=4" id="current">THEMATIQUES</a> 
            <ul id="subnavlist">
                <li id="subactive"><a href="#" id="subcurrent">Lutte contre la corruption</a>
                </li>
                <li><a href="obs-geostrategique-sport.php?cat=4&id=1">Evènements sportifs </a>
                </li>
                <li><a href="obs-geostrategique-sport.php?cat=4&id=2">Bonne gouvernance du sport</a>
                </li>
                <li><a href="obs-geostrategique-sport.php?cat=4&id=3">Economie du sport</a>
                </li>
                <li><a href="obs-geostrategique-sport.php?cat=4&id=4">Lutte contre le dopage</a>
                </li>
                <li><a href="obs-geostrategique-sport.php?cat=4&id=5">Lutte pour l'intégrité dans le sport</a>
                </li>
            </ul>
        </li>
    </ul>
</div>

here is the fiddle http://jsfiddle.net/R8S7q/

Danield
  • 121,619
  • 37
  • 226
  • 255
user2718437
  • 97
  • 1
  • 5

2 Answers2

1

Make sure all your links are display: block; width: 100%; height: 100%; so they fill the parent element. Make sure the parent elements also have width: 100%; height: 100%; so they expand properly.

To center the text itself, see this question: CSS Center text (Horizontal and Vertical) inside a DIV block

Community
  • 1
  • 1
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
1

1) Use line-height on li to center and then revert it to normal on anchor (to deal with multiline text)

2) Place padding / hover classes on li element instead on anchor.

FIDDLE

   ul#navlist li
   {
    padding: 10px 5px 10px 5px;
    background-color: #EF634A;
   }
   ul#navlist > li
   {
    height:62px; /* <----  */
    line-height:62px; /* <----  */
   }
    ul#navlist li:hover
    {
        color: #ffff00;
        background-color: #003366;
    }
    ul#navlist a
    {
    font-weight: bold;
    text-decoration: none;
    display: inline-block;
    line-height:normal; /* <----  */
    vertical-align: middle; /* <----  */
    }
Danield
  • 121,619
  • 37
  • 226
  • 255