Html 这个 CSS 在 Twitter Bootstrap 中的等价物是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8813315/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 12:27:45  来源:igfitidea点击:

What is the equivalent of this CSS in Twitter Bootstrap?

htmlcsstwitter-bootstrap

提问by user847495

<div style="float:left;">
    column 1
</div>
<div style="float:left;">
    column 2
</div>
<div style="clear:both;"></div>

I'm used to writing clear:both. But I heard in Twitter Bootstrap there is something called "clearfix"? On which element should/would I apply "clearfix"?

我习惯了写clear:both。但是我听说在 Twitter Bootstrap 中有一种叫做“clearfix”的东西?我应该/将在哪个元素上应用“clearfix”?

回答by artlung

You probably only have to do:

您可能只需要执行以下操作:

<div class="container">
   <div class="row">
      <div class="span6">column 1</div>
      <div class="span6">column 2</div>
   </div>
</div>

clearfixshould not be necessary.

clearfix应该没有必要。

回答by Philip

using css you can simple use the after psudeo

使用 css 你可以简单地使用 after psudeo

.class1:after, .class2:after //append as many as you like
{
 clear:both;
 *zoom:1;
 height:0;
 visibility: hidden;
 display:block;
}

alternative(providing children are not using the position selector)
(parent-elemts){overflow:hidden;}//bit of a quick fix!

keep unwanted markup out of your html file

将不需要的标记排除在您的 html 文件之外

Edit: sorry! for some reason the add comment button or upvote button is not working for me tonight.

编辑:对不起!出于某种原因,今晚添加评论按钮或投票按钮对我不起作用。

To append my answer to answer your other question:

附加我的答案以回答您的其他问题:

twitter bootstrap you say uses a .clearfix class, which is similar to the css I provided below, however their method needs to be added to the element, ie: "element class="clearfix" OR similar, where as css pseduo's we dont need to add this extra bit of code to our document. Take note however, not all browsers support css pseduo's.

你说的 twitter bootstrap 使用了一个 .clearfix 类,它类似于我在下面提供的 css,但是它们的方法需要添加到元素中,即:“element class="clearfix" 或类似的,其中我们不需要 css pseduo将这些额外的代码添加到我们的文档中。但是请注意,并非所有浏览器都支持 css pseduo。