测试用代码html
<!DOCTYPE html> <html> <head> <style> #dd { //line-height: 300px; background-color: gray; position: relative; font-size: 60px; //height: 300px; } #dd > .middle { position: absolute; top: 50%; height: 1px; background-color: black; left: 0; right: 0px; } #dd span { background-color: green; } </style> </head> <body> <div id="dd"> <img style="height:60px;width:100px;background-color:red;"><span>xg</span> <div class="middle"></div> </div> </body> </html>
默认的是按baseline对齐测试
去掉图片试试:spa
这里xg span的高度是60,68的高度是line-height,上图高72是图片把div撑开了,能够看出span的底部到baseline的距离是83d
给img添加 vertical-align:
bottom; 后:code
图片和div的底边对齐htm
vertical-align:text-bottom
blog
和<span>对齐图片
vertical-align:sub;it
和vertical-align:bottom;相似,可是更低一些io
vertical-align:middle;
图片偏下了
将img的height改为1试一试
原来是跟x居中对齐了