1.手写div垂直水平居中

image-20230224165609299

分两类:一类是固定宽高,一类不需要固定宽高

1.position+margin 负值

子元素必须有固定的宽高

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>01手写div垂直水平居中</title>
</head>

  <style>
    *{
        margin: 0;
        padding: 0;
    }
    .box{
        width: 500px;
        height: 500px;
        border: 5px solid red;
    }
    .item{
        width: 200px;
        height: 300px;
        background-color: #ccc;
    }

  </style>

<body>
    <div class="box">
        <div class="item">01手写div垂直水平居中</div>
    </div>

</body>
</html>

image-20230224165833813

image-20230224174735186

image-20230224174857554

2.position+margin:atuo

image-20230224175133473

3.display:table-cell +vertical-align:middle+margin:auto

这种写法很少用,可以不用固定高度,但是width必须要有值

image-20230224175804761

4.position+transform (不需要固定宽高)

image-20230224180631944

5.flex(不需要宽高)

image-20230224180936608

2.谈谈你对BFC的理解?

image-20230224203803411

1.示例代码1(解决外边距重叠,下面描述有误,并不是margin塌陷):

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        section{
            width: 200px;
            height: 200px;
            background:#ccc;
        }
    </style>
</head>
<body>
    <section>section1</section>
    <section>section2</section>
</body>
</html>

image-20230224204231499

给section 添加一个 margin:50px后

image-20230224204515590

如何解决margin的塌陷?

image-20230224204833031

2.示例代码2(清除浮动):

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        section{
            width: 200px;
            height: 200px;
            background:#ccc;
            margin:20px;
        }
        .box{
            background-color: black;
        }
    </style>
</head>
<body>
    <div class="box">
    <section class="left">left</section>
    <section class="right">right</section>
</div>
</body>
</html>

image-20230224205655653

当给left进行左浮动,right 进行右浮动后

image-20230224210004424

解决办法:

给box添加overflow:hidden; 或者display:inline-block;

image-20230224210219955

image-20230224210309303

以下这些都可以清除浮动

image-20230224210832578

3.你对盒子模型理解多少?

image-20230224210958033

image-20230224214658221

image-20230224221254554

image-20230224221444607

4.如何清除浮动?手写clearfix

image-20230307161007279

image-20230308154225750

1.overflow:hidden

image-20230308154310078

2. 让父级也进行浮动 float:left;

image-20230308154423314

3. 写一个clearfix 的类 ,给父元素添加这个类

.clearfix:after{
    content:'';
    display:block;   // display:table;  table也行
    clear:both;
}

image-20230308154647267

5. margin设置负值后,会怎么样?有何应用?

image-20230308155007211

image-20230308155057278

image-20230308155146184

margin-bottom 下边的元素往上跑

image-20230308155431631

image-20230308155627344

1.margin负值的应用(给父元素添加宽度)

image-20230308155753839

image-20230308155840512

image-20230308160129318

image-20230308160226400

6.如何实现圣杯布局?

image-20230308160348460

image-20230308160532375

image-20230308160436954

想要实现圣杯布局,第一步是要将 元素排列在同一行上面

image-20230308160655540

第二步:实现中间内容宽度的自适应

image-20230308160801022

第三步:提前预留 左右的宽度

image-20230308161012122

第四步:将left-item 移动到最左边

image-20230308161330541

image-20230308161458156

第五步:将right-item 移动到最右边

image-20230308161608956

7.如何实现双飞翼布局?

image-20230308161730989

image-20230308161918134

image-20230308161823565

圣杯布局和双飞翼布局 不同点在于:**html的结构不一样**

第一步:设置元素在同一行上面,并让内容的宽度自适应

image-20230308162207985

第二步:清除浮动的影响,

添加一个div包起来

image-20230308162344329

添加清除浮动的代码

image-20230308162334872

第三步:左右预留空间

image-20230308162528094

第四步:left-item移动到最左边

image-20230308162852117

第五步:right-item移动到最右边

image-20230308162934452

8.px,em,rem ,vh,vw有什么区别?

image-20230308163141249

image-20230308163230371

image-20230308163323222

image-20230308163437591

image-20230308163636680

image-20230308163749706

image-20230308164056375

rem通常用在移动端,通过媒体查询等,进行移动端的适配

image-20230308164328397

image-20230308164445978

9.谈谈你对css选择器优先级的理解?

image-20230308164539596

image-20230308165146295

10.css的哪些样式是可以继承的?

image-20230308165224040

image-20230308165638000

image-20230308165821769

image-20230308165911512