css:只用一个div实现八卦图

8 篇文章 0 订阅

只用一个div实现一个八卦图

效果图
在这里插入图片描述

html

<div></div>

css:

方法一 :(利用边框)
<style>
        div{
            width: 100px;
            height: 200px;
            background: #fff;
            position: absolute;
            left: 0;
            right: 0;
            top:0;
            bottom: 0;
            margin: auto;
            border-style: solid;
            border-color: #000;
            border-width: 1px 100px 1px 1px;
            border-radius: 50%;
        }
        div:before {
            content: '';
            background: #000;
            width: 20px;
            height: 20px;
            border: 40px solid #fff;
            border-radius: 100%;
            position: absolute;
            left: 50%;
            top: 0;
        }
        div:after {
            content: '';
            background: #fff;
            width: 20px;
            height: 20px;
            border: 40px solid #000;
            border-radius: 100%;
            position: absolute;
            right: -50%;
            bottom: 0;
        }
    </style>
方法二 :(利用背景色渐变)
<style>
        div {
            width: 200px;
            height: 200px;
            background: linear-gradient(to right,#000 50%,#fff 50%);   //控制方向及位置,设置50%消除融合部分
            border: 1px solid #000;
            border-radius: 50%;
            position: absolute;
            left: 0;
            right: 0;
            top:0;
            bottom: 0;
            margin: auto;
        }
        div:before {
            content: '';
            background: #000;
            width: 20px;
            height: 20px;
            border: 40px solid #fff;
            border-radius: 100%;
            position: absolute;
            left: 50%;
            top: 0;
            margin-left: -50px;
        }
        div:after {
            content: '';
            background: #fff;
            width: 20px;
            height: 20px;
            border: 40px solid #000;
            border-radius: 100%;
            position: absolute;
            left: 50%;
            bottom: 0;
            margin-left: -50px;
        }
    </style>

补:加一个小小的动画

效果:让八卦图顺时针旋转
html代码

<div></div>

css代码:

<style>
        div{
            width: 100px;
            height: 200px;
            background: #fff;
            position: absolute;
            left: 0;
            right: 0;
            top:0;
            bottom: 0;
            margin: auto;
            border-style: solid;
            border-color: #000;
            border-width: 1px 100px 1px 1px;
            border-radius: 50%;
            animation: change 3s;/*参数1:动画名称;参数2:规定动画完成一个周期所花费的秒或毫秒。默认是 0。*/
            animation-iteration-count: infinite;/*设置动画次数无限[默认值是1]*/
            animation-timing-function: linear;/*使动画匀速旋转[默认值是ease,动画以低速开始,然后加快,在结束前变慢。]*/
        }
        div:before {
            content: '';
            background: #000;
            width: 20px;
            height: 20px;
            border: 40px solid #fff;
            border-radius: 100%;
            position: absolute;
            left: 50%;
            top: 0;
        }
        div:after {
            content: '';
            background: #fff;
            width: 20px;
            height: 20px;
            border: 40px solid #000;
            border-radius: 100%;
            position: absolute;
            right: -50%;
            bottom: 0;
        }
        /*@keyframes:规定动画。*/
        @keyframes change {
            0% {transform: rotate(0deg)}
            100% {transform: rotate(360deg)}
        }
    </style>
  • 6
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值