简体   繁体   English

为什么浮动父级中的空span标签会在新行上呈现?

[英]Why does an empty span tag in a floated parent render on a new line?

I am trying to find out why an empty span tag would render on a new line when it's a child of a floated parent. 我试图找出为什么空的span标记是浮动父代的子代时会在新行上呈现的原因。 I'm sure it's obvious but I can't find the answer. 我敢肯定这很明显,但是我找不到答案。

EDIT: this is not something I'm trying to fix ... more a question for study, so I'm not really looking for a workaround as such. 编辑:这不是我要解决的问题...更多是要研究的问题,因此我并不是真的在寻找这样的解决方法。

EDIT: as pointed out this below this is seemingly specific to chrome 编辑:正如下面指出的那样,这似乎特定于铬

here is my code 这是我的代码

HTML 的HTML

<!-- Example 1  -->
<section>
  <div class = "parent">
    <span>contents</span>
    <span>contents</span>
  </div>
</section>

<!-- Example 2 -->
<section>
  <div class = "parent">
    <span>contents</span>
    <span>contents</span>
    <!-- empty span renders on new line -->
    <span class = "empty"></span> 
  </div>
</section>

CSS 的CSS

.parent{
  float:right;
  background: #666;
  margin-bottom:10px;
}

.parent span {
  font-size: 40px;
  background: pink;
  margin-right: 10px;
}
section {
  clear:both;
}

See CodePen http://codepen.io/anon/pen/ZYGWMR 参见CodePen http://codepen.io/anon/pen/ZYGWMR

The margin-right:10px; margin-right:10px; seems to be causing this behaviour, and only in Chrome. 似乎是造成这种现象的原因,并且仅在Chrome中。

FF and IE both render the span in-line. FF和IE均在线显示跨度。

Adding: 新增:

.empty { display:inline-block; }

seems to make Chrome behave in the same way as FF and IE. 似乎使Chrome的行为与FF和IE相同。

IMHO , this appears to be a bug in Chrome. 恕我直言 ,这似乎是Chrome中的错误。 Perhaps someone can shed some light on that .... Chrome vs FF/IE, which one is right :-) ? 也许有人可以对此有所了解.... Chrome vs FF / IE,哪一个是正确的:-)?

Spans are designed to be embedded or wrapped ie with a <p> tag. 跨度被设计为嵌入或包装,即带有<p>标签。 The span will be treated like a paragraph. 跨度将被视为一个段落。 I think you could add span : inline block to get them to render inline 我认为您可以添加span:inline块以使其呈现内联

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

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