用CSS实现阴阳八卦图等图形

本文介绍如何使用CSS绘制各种几何图形,包括正方形、圆形、椭圆、三角形、梯形和复杂的阴阳八卦图等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

CSS还是比较强大的,可以实现中国古典的“阴阳八卦图”等形状。


正方形



  #rectangle {
      width: 200px;
      height: 100px;
      backgrount-color: red;
  }  #circle {
      width: 100px;
      height: 100px;
      -webkit-border-radius: 100px;
         -moz-border-radius: 100px;
              border-radius: 100px;
      background-color: red;
  }
椭圆

  #triangle-up {
       width: 0;
       height: 0;
       border-left: 50px solid transparent;
       border-right: 50px solid transparent;
       border-bottom: 100px solid red;
  }
直角三角形
直角边left-top

  #triangle-leftbottom {
       width: 0;
       height: 0;
       border-left: 100px solid red;
       border-top: 100px solid transparent;
  }
直角边right-top

  #triangle-righttop {
       width: 0;
       height: 0;
       border-right: 100px solid red;
       border-top: 100px solid transparent;
  }
梯形

  #parallelogram {
       width: 150px;
       height: 100px;
       -webkit-transform: skew(20deg);
          -moz-transform: skew(20deg);
               transform: skew(20deg);
       background: red;
  }

鸡蛋

  #yin-yang {
       width: 96px;
       height: 48px;
       background: #eee;
       border-color: red;
       border-style: solid;
       border-width: 2px 2px 55px 2px;
       border-radius: 100%;
       position: relative;
  }

  #yin-yang:before {
       content: "";
       position: absolute;
       top: 50%;
       left: 0;
       background: #eee;
       border: 18px solid red;
       border-radius: 100%;
       width: 12px;
       height: 12px;
  }

  #yin-yang:after {
       content: "";
       position: absolute;
       top: 50%;
       left: 50%;
       background: red;
       border: 18px solid #eee;
       border-radius:100%;
       width: 12px;
       height: 12px;
  }
八卦图展示不出来,蛋疼,请下载HTML文件 http://download.youkuaiyun.com/detail/huoyingfans/7455161或者 去 http://blog.fansunion.cn/articles/3736 查看
更多文章请参考:http://www.itfriend.cn/user/FansUnion

转载于:https://www.cnblogs.com/qitian1/p/6463285.html

### 实现阴阳八卦图CSS方法 要通过CSS实现阴阳八卦图,可以采用伪元素 `:before` 和 `:after` 来完成复杂的图形设计。以下是具体的实现方式: #### HTML结构 HTML部分非常简单,只需要一个容器即可。 ```html <div class="yinyang"></div> ``` #### CSS样式 下面是完整的CSS代码,用于绘制阴阳八卦图。 ```css .yinyang { position: relative; width: 100px; height: 100px; background-color: black; /* 阴阳外圈背景颜色 */ border-radius: 50%; } /* 白色半圆 */ .yinyang::before { content: ''; position: absolute; top: 0; left: 50%; width: 50%; height: 100%; background-color: white; border-top-right-radius: 100%; border-bottom-right-radius: 100%; } /* 黑色半圆中的白色小圆 */ .yinyang::after { content: ''; position: absolute; top: 25%; left: 15%; width: 10%; height: 50%; background-color: white; border-radius: 50%; } /* 添加黑色小圆 */ .yinyang span { display: block; position: absolute; top: 25%; right: 15%; width: 10%; height: 50%; background-color: black; border-radius: 50%; } ``` 为了使黑白两部分更加平衡,在实际应用中可以通过调整比例参数进一步优化视觉效果[^3]。 #### 关键点解析 - **圆形基础**:通过设置宽高相等并配合 `border-radius: 50%` 创建完美的圆形作为整体框架。 - **伪类运用**:`.yinyang::before` 负责创建右侧白色区域;而 `.yinyang::after` 则用来制作左侧黑区内的小白点。 - **动态布局控制**:借助百分比单位精确设定各组件位置与尺寸关系,从而达成理想的比例分布。 以上方案不仅满足基本功能需求,还具备良好的可维护性和扩展性特点。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值