简体   繁体   中英

links in display:block are not correctly in div with position:absolute

I don't understand why my links are not the .pushMenu divs (left and right),

html:

<header class="header">
    <div class="pushMenu" id="left">
        <a href="" title=""><p>l</p></a>
    </div>
    <div class="pushMenu" id="right">
        <a href="" title=""><p>r</p></a>
    </div>
    <div>
        <span class="myTitle">title</span>
        <span class="myBy">(by me)</span>
    </div>

css:

header {
    text-align: center !important;
    line-height: 60px;
    font-weight: bold;
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 60px;
    color: #ffffff;
}
header div.pushMenu {
    position: absolute;
    width: 30px;
    height: 30px;
    top: 10px;
    border: 1px solid white;
}
header div.pushMenu#left {left: 10px;}
header div.pushMenu#right {right: 10px;}
header div.pushMenu a {
    width: 30px;
    height: 30px;
    display: block;
}

see in action: http://jsfiddle.net/GDQdU/4/

what's wrong ?

This is happening because the line-height specified for the header is being rendered by the child elements also. Check below to correct this.

Remove the p tag from the a tag and the html will be like this <a href="" title="">r</a> and add line-height:30px to the a tag.

header div.pushMenu a{
  line-height:30px;
}

DEMO

OR

If you want the p tag to be there then make the following css changes

header div.pushMenu p{
  margin:0;
  line-height:30px;
}

DEMO

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