css - How to make background color of link take up exact height of container div? -
here's jsfiddle:
here's html:
<div id="header"><ul> <li><a href="#">link 1</a></li> <li><a href="#" id="selected-nav">another link 2</a></li> <li><a href="#">link 3</a></li> </ul></div>
here's css:
body { margin:10px; padding:0; } #header { height:92px; background:#58585a; position:relative; } #header ul { margin:0; padding:0; list-style-type:none; position:absolute; top:35px; right:16px; } #header ul li { display:inline; font-size:1.25em; } #header ul li { color:#ffffff; text-decoration:none; margin-left:1.5em; padding:35px 0; } #selected-nav { background:#ffa31a; }
i have header div has horizontal ul in navigation. have ul absolutely positioned on right side of header div , vertically centered. want highlight current page in navigation. want highlight background color on link , want link bg fill whole height.
the best thing have come with, see above jsfiddle, try , set correct padding on link when change background color take desired height. works on chrome it's off 1 pixel on top , bottom in ff , it's off 1 pixel on bottom in ie. here's screen shot of those:
i tried setting padding go on quite bit , hide overflow-y, did not work.
see solution
css
body { margin:10px; padding:0; } #header { height:92px; background:#58585a; position:relative; } #header ul { margin:0; padding:0; list-style-type:none; position:absolute; top:0px; height:100%; line-height:86px; right:16px; } #header ul li { display:inline; font-size:1.25em; } #header ul li { color:#ffffff; text-decoration:none; margin-left:1.5em; height:100%; display:inline-block; } #selected-nav { background:#ffa31a; }
Comments
Post a Comment