Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

清除浮动的方法 #55

Open
GGXXMM opened this issue Aug 31, 2019 · 0 comments
Open

清除浮动的方法 #55

GGXXMM opened this issue Aug 31, 2019 · 0 comments
Labels

Comments

@GGXXMM
Copy link
Owner

GGXXMM commented Aug 31, 2019

1、创建BFC

1.1 父容器设置overflow(hidden/auto)

1.2 父容器设置position(absolute/fixed)

1.3 父容器设置float

1.4 父容器设置display(inline-block)

2、浮动元素添加空元素,设置clear属性

HTML:

<div class="parent">
    <img src="http://damonare.cn/logo.png" class="fl"/>
    <p class="fr">浮动元素</p>
    <div class="clear"></div>
</div>

CSS:

.fl {
  float: left;
}
.fr {
  float: right;
}
.clear {
  clear: both;
}

3、使用:after伪元素(较为完美的方案)

.clearfix:after {
  content: '.';
  display: block;
  height: 0;
  clear: both;
  visibility: hidden;
}
.cleafix {
  /* 触发haslayout */
  *zoom: 1;
}
@GGXXMM GGXXMM added the css label Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant