How does exactlly line-height work in this case

扶醉桌前 提交于 2019-12-12 04:22:12

问题


In this question positioning text of anchor within a div and given the same code which I repeat here:

HTML Markup

<div id="header"> 
    <a href="cattle.html" class="current">Cattle Farms</a> 
</div> 

CSS Style

#header a { 
    width: 100%; 
    height: 100%; 
    display: block; 
    font-size: 25px; 
} 

Answer

div#header a { 
    width: 100%; 
    height: 100%; 
    display: block; 
    text-indent: 20px; 
    line-height: 350px; 
} 

Fiddle

My question is why does not the line-height make the a break out of the div


回答1:


It does break out of the div. If you put a span inside the a tag and give it a display of inline-block (and a background-color so you can see it) you'll realize it does. Remember the span inherits the line-height. Take a look:

http://jsfiddle.net/fnX9n/6/

Give the a a bigger line-height and without anything else you'll also be able to realize it is breaking out of the div: http://jsfiddle.net/fnX9n/7/



来源:https://stackoverflow.com/questions/12044983/how-does-exactlly-line-height-work-in-this-case

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!