html+css制作五环(代码极简)

奥运五环

把奥运五环做成一个浮动,总是位于屏幕中央的效果。

难点

  1. 定位的练习 position :fixed

  2. 位于body中间的时候 left:50%;top:50%;

  3. css内部样式表的使用 style="text/css"

代码

    <!DOCTYPE html>
    <html >
    <head>
        <meta charset="UTF-8">
        <title>居中五环</title>
        <style type="text/css">
            .a1,.a2,.a3,.a4,.a5{
                    position:absolute;  
                    width: 100px;
                    height: 100px;
                    background-color: transparent;
                    border: 10px solid;
                    border-radius: 110px;
            }
            .plat{
    
                position: fixed;
                top: 50%;
                left: 50%;
                margin-left:-140px;
                margin-top: -70px;
                width: 280px;
                height: 140px;
            }
            .a1{
                border-color: blue;
                left: 0;
                top: 0;
    
            }
            .a2{
                border-color: black;
                top: 0px;
                left: 130px;
                z-index: 4;
            }
            .a3{
                border-color: yellow;
                top: 0px;
                left: 260px;
                z-index: 4;
            }
            .a4{
                border-color: red;
                top: 65px;
                left: 65px;
                z-index: 5;
    
            }
            .a5{
                border-color: green;
                top: 65px;
                left: 198px;
                z-index: 6;
            }
        </style>
        
    <body>
    <div class ="plat"> 
        <div class="a1"></div>
        <div class="a2"></div>
        <div class="a3"></div>
        <div class="a4"></div>
        <div class="a5"></div>
    <div>
        
    </body>
    </html>

效果

猜你喜欢

转载自www.cnblogs.com/gzyc/p/10601198.html
今日推荐