html 和css

2019-04-25  本文已影响0人  不染事非
1、 页面布局

假设高度已知,请写出三列布局,其中左右的各为300px,中间自适应,有四种方法

第一种方法 :浮动
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            .left{
                background: red;
                width: 300px;
                height: 100px;
                float: left;
            }
            .comm{
                background: blue;
                height: 100px;
            }
            .right{
                background: green;
                width: 300px;
                height: 100px;
                float: right;
            }
        </style>
    <body>
           <div class="left"></div>
           <div class="right"></div>
           <div class="comm"></div>
    </body>
</html>
第二种方法 : 定位
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            .left{
             width: 300px;
             height: 300px;
             position: absolute;
             left: 0;
             background: red;
         }
         .right{
             width: 300px;
             height: 300px;
             position: absolute;
             right: 0;
             background: hotpink;
             top:0;
         }
         .center{
             height: 300px;
             background: pink;
             padding:0 300px;
         }
        </style>
    <body>
      <div style="position: relative;">
            <div class="left"></div>
            <div class="center">
                    <h2>绝对定位解决方案</h2>
                    1.这是三栏布局的浮动解决方案;
                    2.这是三栏布局的浮动解决方案;
            </div>
            <div class="right"></div>
      </div> 
    </body>
</html>
第三种 flex布局
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            .fa{
             display: flex;
             /* height: 300px; */
         }
         .center{
             flex: 1;
             background: hotpink;
         }
         .left{
             background: red;
             width: 300px;      
         }
         .right{
             background: pink;
             width: 300px;
         }
        </style>
    <body>
      <div class="fa">
                <div class="left"></div>
                <div class="center">
                    <h2>flex解决方案</h2>
                    1.这是三栏布局的浮动解决方案;
                    2.这是三栏布局的浮动解决方案;
                </div>
                <div class="right"></div>    
      </div> 
    </body>
</html>
第四种 网格布局(CSS最新增的,类似于bootstrap的栅格系统)
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
    fu{
        display: grid;
        grid-template-rows: 300px;
               grid-template-columns: 300px auto 300px;
    }
    .left{
        background: red;
    }
    .right{
        background: hotpink;
    }
    .center{
        background: pink;
    }
</style>
<body>
     <div class="fu">
                <div class="left"></div>
                <div class="center">
                    <h2>网格布局解决方案</h2>
                    1.这是三栏布局的浮动解决方案;
                    2.这是三栏布局的浮动解决方案;
                </div>
                <div class="right"></div>
        </div> 
    </body>
</html>

若高度不给,那么高度能自适应的只有 flex 布局和 表格布局,网格布局了,其他则不可以

2、css 盒模型

2.1、css如何设置这2种模型
2.2 js如何设置获取盒模型对应的宽和高:

3、BFC(边距重叠解决方案)

3.1、什么是BFC
3.2 原理
3.3 怎么创建BFC
3.4、BFC有什么用

4、如何实现不确定宽高的盒子上下左右居中

div{
      position:absolute;
      top:50%; //相对于父元素
      left:50%; //相对于父元素
      transform:translate(-50%,-50%); //相对于自己
   }

5、如何实现不确定宽高的图片上下左右居中

 img{
     position:absolute;
      top:0; /* 四周拉力相同 */
      right:0; /* 四周拉力相同 */
      bottom:0; /* 四周拉力相同 */
      left:0; /* 四周拉力相同 */
      margin:auto; /* 再设置 marign 自动 */
    }

6、纯css写倒三角的原理:

.kailong{
    width:0;
    height:0;
    border-right:50px solid transparent;
    border-left:50px solid transparent;
    border-bottom:50px solid red;
}
上一篇 下一篇

猜你喜欢

热点阅读