简体   繁体   中英

CSS padding in the li>a elements

I want to align the fonts so that they appear at center while not increasing the maximum height of #nav li a above 60px. Please suggest a way. max-height didn't work in this case.

HTML

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div>
        <ul id="nav">
            <li><a href="#">Work</a></li>
            <li><a href="#">Blog</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </div>
</body>
</html>

CSS

#nav {
list-style-type: none;
margin: 0;
padding: 0;
}
#nav li {
width: 20%;
float: right;
text-align:center;
}
#nav li a {
height:60px;
display: block;
padding: 0.5em 5px 0.5em 5px;
text-decoration: none;
font-weight: bold;
color: #F2F2F2;
}
#nav a:link, #nav a:visited {
background-color: #071726;
}
#nav a:hover, #nav a:active, #nav a:focus {
background-color: #326773;
}

Add line-height:60px to #nav li a .

Here is the fiddle .

Added a line-height attribute to the nav links in your CSS. Check it out: http://jsfiddle.net/2xEz2/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM