A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

### 盒模型

```
/* 红色区域的大小是多少?200 - 20*2 - 20*2 = 120 */
.box {
    width: 200px;
    height: 200px;
    padding: 20px;
    margin: 20px;
    background: red;
    border: 20px solid black;
    box-sizing: border-box;
}
```

```
/* 标准模型 */
box-sizing:content-box;
/*IE模型*/
box-sizing:border-box;
```

[回到顶部](https://www.cnblogs.com/chenwenhao/p/11217590.html#_labelTop)

### 如何实现一个最大的正方形

用 `padding-bottom` 撑开边距

```
section {
    width:100%;
    padding-bottom: 100%;
    background: #333;
}
```

[回到顶部](https://www.cnblogs.com/chenwenhao/p/11217590.html#_labelTop)

### 一行水平居中,多行居左

```
<div><span>我是多行文字。我是多行文字。我是多行文字。我是多行文字。我是多行文字。我是多行文字。我是多行文字。我是多行文字。我是多行文字。我是多行文字。</span></div>
<div><span>我是一行文字</span></div>

<style>
div{text-align: center;}
div span{display: inline-block;text-align: left;}
</style>
```

[回到顶部](https://www.cnblogs.com/chenwenhao/p/11217590.html#_labelTop)

### 水平垂直居中

贴上腾讯大佬的一篇文章:[16种方式实现水平居中垂直居中](https://juejin.im/post/58f818bbb123db006233ab2a)

# 两栏布局,左边固定,右边自适应,左右不重叠

flex做自适应布局很容易,但兼容性不好,这里统一不用flex布局

```
.left{
    float:left;
    width:300px;
    margin-right: 10px;
    background: red;
}
.right{
    overflow: hidden; /* 创建BFC */
    background: yellow;
}
```

[回到顶部](https://www.cnblogs.com/chenwenhao/p/11217590.html#_labelTop)

### 如何实现左右等高布局

`table`布局兼容性最好,当然`flex`布局的`align-items: stretch;`也行

```
<div class="layout">
  <div class="layout left">left</div>
  <div class="layout right">center</div>
</div>

<style>
.layout{
  display: table;
  width: 100%;
}
.layout div{
  display: table-cell;
}
.layout .left{
  width: 50%;
  height: 200px;
  background: red;
}
.layout .right{
  width: 50%;
  background: yellow;
}
</style>
```

[回到顶部](https://www.cnblogs.com/chenwenhao/p/11217590.html#_labelTop)

### 画三角形

```
.shape {
    width: 0;
    height: 0;
    border-left: 50px solid transparent;
    border-right: 50px solid transparent;
    border-top: 50px solid transparent;
    border-bottom: 50px solid blue;
    background: white;
}
```

[回到顶部](https://www.cnblogs.com/chenwenhao/p/11217590.html#_labelTop)

### link @import导入css

1.  link是XHTML标签,除了加载CSS外,还可以定义RSS等其他事务;@import属于CSS范畴,只能加载CSS
2.  link引用CSS时,在页面载入时同时加载;@import需要页面网页完全载入以后加载
3.  link无兼容问题;@import是在CSS2.1提出的,低版本的浏览器不支持
4.  link支持使用Javascript控制DOM去改变样式;而@import不支持

[回到顶部](https://www.cnblogs.com/chenwenhao/p/11217590.html#_labelTop)

### BFC理解

BFC触发条件:

1.  根元素,即html
2.  float的值不为none(默认)
3.  position的值为absolute或fixed
4.  overflow的值不为visible(默认)
5.  display的值为inline-block、table-cell、table-caption

BFC特性:

1.  内部的Box会在垂直方向上一个接一个放置。
2.  Box垂直方向的距离由margin决定,属于同一个BFC的两个相邻Box的margin会发生重叠。
3.  每个元素的margin box 的左边,与包含块border box的左边相接触。
4.  BFC的区域不会与float box重叠。(可用于清浮动)
5.  BFC是页面上的一个隔离的独立容器,容器里面的子元素不会影响到外面的元素。
6.  计算BFC的高度时,浮动元素也会参与计算。

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马