简体   繁体   English

如何防止IE删除“空”文本节点

[英]How to prevent IE from removing an “empty” text node

I've build a navigation using the text-justify method with inline-block child elements and it all works great everywhere except IE. 我使用带有内联块子元素的text-justify方法构建了一个导航,除了IE之外,所有其他方法都很好用。 Because of HTML minification that I don't have control over, I added a space character (   ) between the child elements, which makes the justification actually work. 由于我无法控制HTML的缩小,因此我在子元素之间添加了一个空格字符(   ),这使得该对齐实际上可行。 Now, I cannot figure out how to make IE leave that space node alone and not treat it as empty. 现在,我无法弄清楚如何使IE独自留下该空间节点而不将其视为空。

Example here: http://codepen.io/anon/pen/cAskd 此处的示例: http : //codepen.io/anon/pen/cAskd

<ul>
  <li></li>
  <li></li>
  <li></li>
</ul>

ul {
  text-align: justify;
  font-size: 0;
  list-style: none;
  width: 50%;
  &:after {
    content: "";
    width: 100%;
    display: inline-block;
  }
  > * {
    display: inline-block;
    vertical-align: middle;
    width: 20%;
    height: 2em;
    background: gray;
    border: 1px solid red;
    font-size: 10px;
  }
}

From Justify Grid - 对齐网格 -

Internet Explorer has an issue with font-size: 0; Internet Explorer的font-size: 0;有问题font-size: 0; causing whitespace to collapse instead of expanded by justify aligning. 导致空格折叠,而不是通过对齐对齐扩展。 There are other ways to hide the pseudo-element like line-height: 0; 还有其他隐藏伪元素的方法,例如line-height: 0; but Justify Grid is using font-size because it's fixing a Chrome issue as well. 但是Justify Grid正在使用字体大小,因为它也解决了Chrome问题。 Internet Explorer has an easy solution anyway, text-justify: distribute-all-lines ; 无论如何,Internet Explorer都有一个简单的解决方案, text-justify: distribute-all-lines

Forked pen with solution (tested in IE9+) - 带有解决方案的分叉笔(在IE9 +中测试)-

http://codepen.io/clintioo/pen/ynvhK http://codepen.io/clintioo/pen/ynvhK

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM