CSS中BFC(还有margin-top和top)

本文介绍了CSS中的布局方式,包括标准流、浮动布局、定位布局和弹性布局。重点讨论了BFC(Block Formatting Context)的概念,它是CSS布局中的一种重要机制,用于理解元素定位和外边距重叠。BFC可以通过特定条件触发,如根元素、浮动、overflow值等。同时,BFC在解决浮动元素高度塌陷和防止元素被覆盖等问题上起到关键作用。
摘要由CSDN通过智能技术生成

1.前置知识介绍

HTML中常用布局方式:
1.标准流/普通流
2.浮动布局
3.定位布局
4.弹性布局

块级元素:div、H1-H5、p、table、ol/ul/li

内联元素(可置换/不可置换):a、span、img、input

margin-top和top附注:

top/right/bottom/left和margin-top/margin-right/margin-bottom/margin-left都可以用在relative/absolute中,但是relative一般用margin-top/margin-right/margin-bottom/margin-left,absolute一般用top/right/bottom/left(absolute中使用margin-top是一种特殊的“相对定位”),两者的区别,可以通过查看盒模型知道。

还有一条:
1.使用top、bottom、left、right的前提是本元素position被定义为relative、absolute和fixed中的一种,不能是static
2.使用margin-top、margin-bottom、margin-left、margin-right的元素的position可以是static、relative、absolute和fixed
3.relative下right和bottom是从right/bootom方向偏移,比如

position: relative;
background: blue;
width: 100px;
height: 100px;
right: 50px;
bottom: 50px;

是从right/bottom方向偏移50px࿰

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值