Skip to content


display:inline-block 额外产生的4px margin

今天在做一个Timeline的模块的时候遇到一个棘手的问题: 给元素添加display:inline-block 属性的时候会产生额外的4px的margin-right。

原始代码

.YP_timelineChart_box li{
display:-moz-inline-stack;
display:inline-block;
zoom:1;
*display:inline;
text-indent:-3000px;
width:5px;
vertical-align:bottom;
background-color:#00FF00;
position:relative;
}

页面渲染结果:

每一列都会向右产生外边距4px,苦思不得其解,尝试负的外边距,但是涉及到其他的问题:每个li标签会重叠1-2个px,妨碍到鼠标hover状态的事件。尝试修改doctype类型也不见效果。后来尝试了另外一个方法:

把原来的HTML 代码结构:

更改为:

这样就不会产生额外的外边距,也弄不清楚为什么会出现这种问题。先暂时记下,以后再研究研究。

Posted in 前端开发.

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

You must be logged in to post a comment.