css how to make <a> text align bottom?

不羁的心 提交于 2019-12-08 03:06:18

问题


How how to make <a> text align bottom? I have added height = line-height, and vertical-align:bottom; but the text still in the middle of the div. How to do? Thanks

Test in http://jsfiddle.net/BanAz/

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style type="text/css">
#layer{width:198px;height:48px;line-height:48px;border:1px #000 solid;vertical-align:bottom;}
#layer a{text-decoration:none;}
</style>
</head>
<body>
<div id="layer">
<a href="#">menu</a>
</div>
</body>
</html>

回答1:


Options include:

  • Remove line-height: 48px and add display: table-cell to #layer: http://jsfiddle.net/jgQ9k/1/
    Note that this won't work for IE7, because display: table-cell isn't supported.
  • Use a large line-height: http://jsfiddle.net/jgQ9k/2/

And the method I would actually use:

  • Add position: relative to #layer, and position:absolute; bottom:0 to #layer a:
    http://jsfiddle.net/jgQ9k/3/



回答2:


The height size (48px) is equal to line-height size (48px). Try to increase the height size, and you will see the css properties work fine and the text will be positioned on the bottom




回答3:


#layer {
    display: table-cell;
}


来源:https://stackoverflow.com/questions/5928849/css-how-to-make-a-text-align-bottom

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