display:inline-block的bug 空白节点

display:inline-block的bug 当有空白节点出现的时候,就会有很大的间隙:

<!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=utf-8" />
<title>无标题文档</title>
<style>
* { margin: 0; padding: 0; }
a { text-decoration: none; }
#retrieve { padding: 19px 0 0 16px; }
#retrieve a { font-size: 14px; background: none repeat scroll 0 0 #F3F2EA; display: inline-block; font-weight: bold; height: 18px; line-height: 20px; margin: 0 1px; text-align: center; width: 18.5px; }
#retrieve a:hover { background: none repeat scroll 0 0 #FF0000; color: #FFFFFF; }
</style>
</head>

<body>
<div id="retrieve"><a href="#">A</a><a href="#">B</a><a href="#">C</a> <a href="#">D</a><a href="#">E</a><a href="#">F</a><a href="#">G</a><a href="#">H</a><a href="#">I</a> <a href="#">J</a><a href="#">K</a><a href="#">L</a><a href="#">M</a><a href="#">N</a><a href="#">O</a><a href="#">P</a><a href="#">Q</a><a href="#">R</a><a href="#">S</a><a href="#">T</a><a href="#">U</a><a href="#">V</a><a href="#">W</a><a href="#">X</a><a href="#">Y</a><a href="#">Z</a></div>
</body>
</html>

  修正bug(给父元素加上font-size:0;):

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>无标题文档</title>
 6 <style>
 7 * { margin: 0; padding: 0; }
 8 a { text-decoration: none; }
 9 #retrieve { padding: 19px 0 0 16px; font-size:0;}
10 //↑↑↑↑↑↑↑给父元素加font-size:0;↑↑↑↑
11 #retrieve a { font-size: 14px; background: none repeat scroll 0 0 #F3F2EA; display: inline-block; font-weight: bold; height: 18px; line-height: 20px; margin: 0 1px; text-align: center; width: 18.5px; }
12 #retrieve a:hover { background: none repeat scroll 0 0 #FF0000; color: #FFFFFF; }
13 </style>
14 </head>
15 
16 <body>
17 <div id="retrieve"><a href="#">A</a><a href="#">B</a><a href="#">C</a> <a href="#">D</a><a href="#">E</a><a href="#">F</a><a href="#">G</a><a href="#">H</a><a href="#">I</a> <a href="#">J</a><a href="#">K</a><a href="#">L</a><a href="#">M</a><a href="#">N</a><a href="#">O</a><a href="#">P</a><a href="#">Q</a><a href="#">R</a><a href="#">S</a><a href="#">T</a><a href="#">U</a><a href="#">V</a><a href="#">W</a><a href="#">X</a><a href="#">Y</a><a href="#">Z</a></div>
18 </body>
19 </html>

 

转载于:https://www.cnblogs.com/the0ne/articles/3257656.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值