CSS3学习第五天

1、多列布局

案例:

代码:


<!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>
        .box{
            column-count: 5;
            background-image: url(images/19.gif);
        }
        .box img{
            width: 100%;
        }
        .box div{
            border: 3px solid green;
            padding: 5px;
            margin-bottom: 10px;
            /* 禁止盒子内部折行显示 */
            break-inside: avoid;
        }
        .box div p{
            line-height: 30px;
            text-align: center;
            font-size: 16px;
        }
    </style>
</head>
<body>
    <div class="box">
        <div>
            <img src="images/1.jpg" alt="">
            <p>中国演员</p>
        </div>
        <div>
            <img src="images/2.jpg" alt="">
            <p>中国演员</p>
        </div>        
        <div>
            <img src="images/3.jpg" alt="">
            <p>中国演员</p>
        </div>
        <div>
            <img src="images/4.jpg" alt="">
            <p>中国演员</p>
        </div>
        <div>
            <img src="images/5.jpg" alt="">
            <p>中国演员</p>
        </div>
        <div>
            <img src="images/6.jpg" alt="">
            <p>中国演员</p>
        </div>
        <div>
            <img src="images/7.jpg" alt="">
            <p>中国演员</p>
        </div>
        <div>
            <img src="images/8.jpg" alt="">
            <p>中国演员</p>
        </div>
        <div>
            <img src="images/9.jpg" alt="">
            <p>中国演员</p>
        </div>
        <div>
            <img src="images/10.jpg" alt="">
            <p>中国演员</p>
        </div>
        <div>
            <img src="images/11.jpg" alt="">
            <p>中国演员</p>
        </div>
        <div>
            <img src="images/12.jpg" alt="">
            <p>中国演员</p>
        </div>
        <div>
            <img src="images/13.jpg" alt="">
            <p>中国演员</p>
        </div>
        <div>
            <img src="images/14.jpg" alt="">
            <p>中国演员</p>
        </div>
        <div>
            <img src="images/15.jpg" alt="">
            <p>中国演员</p>
        </div>
        <div>
            <img src="images/16.jpg" alt="">
            <p>中国演员</p>
        </div>
        <div>
            <img src="images/17.jpg" alt="">
            <p>中国演员</p>
        </div>
        <div>
            <img src="images/18.jpg" alt="">
            <p>中国演员</p>
        </div>
    </div>
</body>
</html>

2、响应式布局

 

 

 

 

 

 

3、响应式布局案例

效果:

  

 代码:


<!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>
        *{
            padding: 0px;
            margin: 0px;
        }
        .top{
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
        }
        .top>div{
            width: 49%;
            display: flex;
        }
        .top img{
            width: 100%;
            height: 100%;
        }
        .top .right {
            display: flex;
            justify-content: space-between;
        
        }
        .top .right>div{
            width: 49%;
        }
        @media screen and (max-width:768px){
            .top>div{
                width: 100%;
            }
        }
        .bottom{
            display: flex;
            flex-wrap: wrap;
            justify-content: space-around;
        }
        .bottom>div{
            width: 24%;
            padding: 5px;
            box-sizing: border-box;
            border: 1px solid gray;
            
            margin-bottom: 10px;
            box-shadow: 0 0 5px black;
        }
        .bottom img{
            width: 100%;
        }
        @media screen and (max-width:1024px) and (min-width:768px){
            .bottom>div{
                width: 31%;
            }
        }
        @media screen and (max-width:768px) and (min-width:450px){
            .bottom>div{
                width: 48%;
            }
        }
        @media screen and (max-width:450px) {
            .bottom>div{
                width: 100%;
            }
        }
    </style>
</head>
<body>
    <!-- 
        top: flex,wrap
            >768px   左 49%   右49%
            <768px   上100%  下100%

        bottom:flex,wrap
            >1024   25%*4
            768>   <1024    31%*3
            
            450>   <768     48%*2
            <450      90%*1
     -->
     <div class="top">
         <div class="left">
             <img src="images/1.jpg" alt="">
         </div>
         <div class="right">
             <div>
                 <img src="images/2.jpg" alt="">
             </div>
             <div>
                <img src="images/3.jpg" alt="">
             </div>
         </div>
     </div>

     <div class="bottom">
         <div>
             <img src="images/4.jpg" alt="">
             <p>
                 迷你微型摄影展

             </p>
         </div>
         <div>
            <img src="images/4.jpg" alt="">
            <p>
                迷你微型摄影展

            </p>
        </div>
        <div>
            <img src="images/4.jpg" alt="">
            <p>
                迷你微型摄影展

            </p>
        </div>
        <div>
            <img src="images/4.jpg" alt="">
            <p>
                迷你微型摄影展

            </p>
        </div>
        <div>
            <img src="images/4.jpg" alt="">
            <p>
                迷你微型摄影展

            </p>
        </div>
        <div>
            <img src="images/4.jpg" alt="">
            <p>
                迷你微型摄影展

            </p>
        </div>
        <div>
            <img src="images/4.jpg" alt="">
            <p>
                迷你微型摄影展

            </p>
        </div>
        <div>
            <img src="images/4.jpg" alt="">
            <p>
                迷你微型摄影展

            </p>
        </div>
     </div>
</body>
</html>

4、em和rem

px:50px

em:相对单位,相对于父元素的字体大小。

rem:相对单位,相对于根元素html字体大小。

5、rem布局准备工作

vscode插件 

 

这个插件默认只能转化16px

需要改变16px,需要在vscode中选中文件->首选项->设置->在搜索里边打上“px”,把16这个值改成别的值就行

6、足球圈rem布局

效果:换不同型号的设备,缩放比例差不多

 代码:


<!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>
    <link rel="stylesheet" href="font/iconfont.css">
    <style>
        *{
            margin: 0%;
            padding: 0%;
        }
        ul{
            list-style: none;
        }
        html,body{
            height: 100%;
        }
        html{
            font-size: 16px;
        }
        body{
            display: flex;
            flex-direction: column;
        }
        header{
            height: 2.75rem;
            background: #0cc420;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        header div{
            width: 3.75rem;
            height: 1.5625rem;
            line-height: 1.5625rem;
            text-align: center;
            font-size: .75rem;
            color: white;
        }
        header div:nth-child(1){
            border-radius: .75rem 0 0 .75rem;
            background: #63d985;
           
        }
        header div:nth-child(2){
            border-radius: 0 .75rem .75rem 0;
            background: #6dd006;
         
        }


        section{
            flex: 1;
            overflow: auto;
        }
        section ul{
            position: sticky;
            top: 0rem;
            display: flex;
            background: white;
        }
        section ul li{
            flex: 1;
            text-align: center;
            height: 2.1875rem;
            line-height: 2.1875rem;
            border-bottom: .0625rem solid #d9d9d9;
            color: #8c8c8c;
            font-size: .875rem;
        }
        section ul li:hover{
            border-bottom: .125rem solid #08c63e;
            color: #08c63e;
        }
        section .list{
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
        }
        section .list>div{
            width: 49%;
            margin-top: .25rem;
            border: 1px solid grey;
        }
        section .list>div img{
            width: 100%;
          
        }
        section .list>div p{
            height: 1.875rem;
            line-height: 1.875rem;
            font-size: .75rem;
            text-indent: .625rem;
        }

        

        footer{
            height: 2.75rem;
            background: white;
            color: #d5d5d7;
            
        }
        footer ul{
            display: flex;
            height: 100%;
        }
        
        footer li{
            height: 100%;
            flex: 1;
            display: flex;
            flex-direction: column;
            justify-content: center;
        }
        footer li:hover{
            color: #08ca43;
        }
        footer li i{
            height: 1.3125rem;
            line-height: 1.3125rem;
            text-align: center;
            font-size: 1rem;
        }
        footer li span{
            height: 1.0625rem;
            line-height: 1.0625rem;
            font-size: .75rem;
            text-align: center;
        }
        footer li:nth-child(3){
            position: relative;
        }
        footer li:nth-child(3) i{
            width: 3.125rem;
            height: 3.125rem;
            border: .0625rem solid #dadada;
            border-radius: 50%;
            position: absolute;
            left: 50%;
            margin-left: -1.5625rem;
            top:-0.5rem;
            font-size: 1.875rem;
            text-align: center;
            line-height: 3.125rem;
            background: white;
          
        }
        .iconfont{
            font-size: 1rem;
        }
    </style>
    <script>
        document.documentElement.style.fontSize=document.documentElement.
        clientWidth/320 * 20 +"px"
    </script>
</head>
<body>
    <header>
        <div>热点</div>
        <div>关注</div>
    </header>

    <section>
        <ul>
            <li>足球现场</li>
            <li>足球生活</li>
            <li>足球美女</li>
        </ul>
        <div class="list">
            <div>
                <img src="1.png">
                <p>大家好大家好</p>
            </div>
            <div>
                <img src="1.png">
                <p>大家好大家好</p>
            </div>
            <div>
                <img src="1.png">
                <p>大家好大家好</p>
            </div>
            <div>
                <img src="1.png">
                <p>大家好大家好</p>
            </div>
            <div>
                <img src="1.png">
                <p>大家好大家好</p>
            </div>
            <div>
                <img src="1.png">
                <p>大家好大家好</p>
            </div>
        </div>
    </section>

    <footer>
        <ul>
            <li>
                <i class="iconfont icon-shouye"></i>
                <span>首页</span>
            </li>

            <li>
                <i class="iconfont icon-shouye"></i>
                <span>首页</span>
            </li>

            <li>
                <i class="iconfont icon-xiangji"></i>
            </li>

            <li>
                <i class="iconfont icon-shouye"></i>
                <span>首页</span>
            </li>
            
            <li>
                <i class="iconfont icon-shouye"></i>
                <span>首页</span>
            </li>
        </ul>
    </footer>
</body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值