首页 > Web开发 > 详细

实现CSS圆环

时间:2020-05-29 01:13:47      阅读:66      评论:0      收藏:0      [点我收藏+]
  1. 使用border
    技术分享图片
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style>
            div{
                width: 200px;
                height: 200px;
                background: brown;
                border: 50px solid greenyellow;
                border-radius: 50%;
            }
        </style>
    </head>
    <body>
        <div></div>
    </body>
    </html>
    View Code
  2. 两个嵌套div
    技术分享图片
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style>
            .father{
                width: 200px;
                height: 200px;
                background: greenyellow;
                border-radius: 50%;
            }
            .son{
                width: 100px;
                height: 100px;
                background: brown;
                border-radius: 50%;
    
                position: relative;
                top: 50px;
                left: 50px;
    
                /* position: relative;
                top: 50px;
                left: 50px; */
            }
        </style>
    </head>
    <body>
        <div class="father">
            <div class="son"></div>
        </div>
    </body>
    </html>
    定位
    技术分享图片
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style>
            .father{
                width: 200px;
                height: 200px;
                background: greenyellow;
                border-radius: 50%;
                
                position: absolute;
                /* position: fixed;
                float: left/right;
                overflow: hidden;
                display: inline-block; */
            }
            .son{
                width: 100px;
                height: 100px;
                background: brown;
                border-radius: 50%;
                margin: 50px;
            }
        </style>
    </head>
    <body>
        <div class="father">
            <div class="son"></div>
        </div>
    </body>
    </html>
    触发父级bfc
  3. 使用伪元素,before/after
    技术分享图片
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style>
            div{
                width: 200px;
                height: 200px;
                background-color: greenyellow;
                border-radius: 50%;
            }
            div::before{
                content: "";
                display: block;
                width: 100px;
                height: 100px;
                border-radius: 50%;
                background-color: brown;
    
                position: relative;
                top: 50px;
                left: 50px;
                
                /* position: absolute;
                margin: 50px; */
            }
        </style>
    </head>
    <body>
        <div></div>
    </body>
    </html>
    View Code
  4. 使用border-shadow
    技术分享图片
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style>
            div{
                width: 200px;
                height: 200px;
                background-color: greenyellow;
                border-radius: 50%;
                box-shadow: 0 0 0 50px brown inset;
            }
        </style>
    </head>
    <body>
        <div></div>
    </body>
    </html>
    View Code
  5. 使用radial-gradient
    技术分享图片
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style>
            div{
                width: 200px;
                height: 200px;
                border-radius: 50%;
                background: -webkit-radial-gradient( circle closest-side,greenyellow 50%,brown 50%);
            }
        </style>
    </head>
    <body>
        <div></div>
    </body>
    </html>
    径向渐变

     

  

实现CSS圆环

原文:https://www.cnblogs.com/Rooney10/p/12984841.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!