为了账号安全,请及时绑定邮箱和手机立即绑定

为什么a标签在div里面没有垂直居中?

为什么a标签在div里面没有垂直居中?

慕沐8531599 2017-11-23 01:35:19
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>零食网站</title></head><style>*{padding:0;margin:0}.top{height:37px; width:100%;background-color:black;}.body{border:1px solid red; height:100%;width:1000px;margin:0 auto;}.top a{font-size:15px;color:white;line-height:10px;height:10px;}</style><body><div class="top">   <img src="G:图片/美食.png">   <a href="">首页</a>   <a href="">菜谱</a>   <a href="">食材</a>   <a href="">珍选</a>   <a href="">健康</a>   <a href="">专题</a>   <a href="">社区</a>   <a href="">话题</a>   <a href="">活动</a>   <a href="">搜索</a> </div><div class="body"></div></body></html>
查看完整描述

3 回答

?
realwds

TA贡献69条经验 获得超24个赞

你的a标签已经在a内垂直居中了,如果你想在div内垂直居中,需要把a标签内的line-height改成div的高度

查看完整回答
2 反对 回复 2017-11-23
  • 慕沐8531599
    慕沐8531599
    改了也没用
  • realwds
    realwds
    .top a{font-size:15px;color:white;line-height:37px;height:10px;} 这样! 我试了好使啊,a垂直居中了
?
努力奋斗的小黄人

TA贡献5条经验 获得超1个赞

可以 .top a{display:table-cell;vertical-align:middle;}

查看完整回答
反对 回复 2017-11-23
?
juymy

TA贡献2条经验 获得超1个赞

.top a{font-size:15px;color:white;line-height:37px;height:37px;}


查看完整回答
反对 回复 2017-11-23
?
葙濡姒沫

TA贡献4条经验 获得超0个赞

跟a给个margin不行吗?

查看完整回答
反对 回复 2017-11-23
  • 3 回答
  • 0 关注
  • 10328 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信