【HTML】CSS绘制奥运五环

文章目录

CSS绘制奥运五环

1.伪元素遮盖法

html 复制代码
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>奥运五环-伪元素遮盖法</title>
    <style>
      /*
              * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        } */
        
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            padding: 20px;
        }
        
        .container {
            text-align: center;
            max-width: 800px;
            padding: 30px;
            background-color: rgba(255, 255, 255, 0.9);
            border-radius: 20px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }
        
        h1 {
            color: #2c3e50;
            margin-bottom: 10px;
            font-family: "楷体";
            font-size: 3.4rem;
            text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1);
        }
        
        .subtitle {
            color: #7f8c8d;
            margin-bottom: 30px;
            font-size: 1.2rem;
        }

        .olympics-container {
            position: relative;
            width: 600px;
            height: 400px;
            margin: 0 auto 40px;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        
        /*奥运五环的CSS属性*/
        
        .ring {
            position: absolute;
            width: 200px;
            height: 200px;
            border-radius: 50%;
            border-width: 20px;
            border-style: solid;
            top: -20px;
            right: -20px;
        }
        .green {
            color: #30a751;
            top: 70px;
            right: -160px;
            z-index: 2;
        }
        .black {
            position: relative;
            width: 200px;
            height: 200px;
            border-radius: 50%;
            border-width: 20px;
            border-style: solid;
            margin: 10vw auto;
        }
        .black::before {
            content: "";
            position: absolute;
            width: 200px;
            height: 200px;
            border-radius: 100%;
            top: -20px;
            right: -20px;
            border: 20px solid transparent;
            border-bottom: 20px solid currentcolor;
            z-index: 1;
        }
        .black::after {
            content: "";
            position: absolute;
            width: 200px;
            height: 200px;
            border-radius: 100%;
            top: -20px;
            right: -20px;
            border: 20px solid transparent;
            border-right: 20px solid currentcolor;
            z-index: 3;
        }
        .red {
            color: #ef314e;
            right: -275px;
        }
        .red::after {
            content: "";
            position: absolute;
            width: 200px;
            height: 200px;
            border-radius: 50%;
            border-width: 20px;
            border-style: solid;
            top: -20px;
            right: -20px;
            border: solid 20px transparent;
            border-bottom: solid 20px currentcolor;
            z-index: 2;
        }
        .yellow {
            color: #fcb32e;
            top: 70px;
            left: -138px;
        }
        .blue {
            color: #0082c9;
            left: -273px;
        }
        .blue::after {
            content: "";
            position: absolute;
            width: 200px;
            height: 200px;
            border-radius: 50%;
            border-width: 20px;
            border-style: solid;
            top: -20px;
            right: -20px;
            border: solid 20px transparent;
            border-right: solid 20px currentcolor;
            z-index: 2;
        }

        /**/
        /* 奥运五环标志 */
        .olympic-symbol {
            font-size: 1.5rem;
            color: #2c3e50;
            margin-top: 20px;
            letter-spacing: 2px;
            font-weight: bold;
        }

        
        /* 环的颜色说明 */

        .blue-color { background-color: #0085C7; }
        .yellow-color { background-color: #F4C300; }
        .black-color { background-color: #000000; }
        .green-color { background-color: #009F3D; }
        .red-color { background-color: #DF0024; }

        .color-info {
            display: flex;
            justify-content: center;
            flex-wrap: wrap;
            gap: 15px;
            margin-top: 30px;
        }
        
        .color-item {
            display: flex;
            align-items: center;
            margin: 5px 10px;
        }
        
        .color-box {
            width: 20px;
            height: 20px;
            border-radius: 3px;
            margin-right: 8px;
        }
        
        .footer {
            margin-top: 30px;
            color: #7f8c8d;
            font-size: 0.9rem;
        }
    </style>
  </head>
  <body>
    <div class="container">
      <h1>奥运五环</h1>
      <p class="subtitle">使用纯HTML和CSS绘制 - 代表五大洲的团结</p>
      <div class="olympics-container">
        <div class="black">
          <div class="ring blue"></div>
          <div class="ring yellow"></div>
          <div class="ring green"></div>
          <div class="ring red"></div>
        </div>
      </div>

      <div class="olympic-symbol">OLYMPIC RINGS</div>

      <div class="color-info">
        <div class="color-item">
          <div class="color-box blue-color"></div>
          <span>蓝色 - 欧洲</span>
        </div>
        <div class="color-item">
          <div class="color-box yellow-color"></div>
          <span>黄色 - 亚洲</span>
        </div>
        <div class="color-item">
          <div class="color-box black-color"></div>
          <span>黑色 - 非洲</span>
        </div>
        <div class="color-item">
          <div class="color-box green-color"></div>
          <span>绿色 - 大洋洲</span>
        </div>
        <div class="color-item">
          <div class="color-box red-color"></div>
          <span>红色 - 美洲</span>
        </div>
      </div>

      <div class="footer">
        <p>奥运五环标志由皮埃尔·德·顾拜旦于1913年设计,五个环代表五大洲,六种颜色(含白色背景)代表当时所有国家的国旗颜色</p>
        <p style="margin-top: 10px;">少莫千华 | 纯CSS实现 | 无JavaScript | 响应式设计</p>
      </div>
    </div>
  </body>
</html>

2.元素旋转法

html 复制代码
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>奥运五环-元素旋转法</title>
    <style>
      /*
              * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        } */
        
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            padding: 20px;
        }
        
        .container {
            text-align: center;
            max-width: 800px;
            padding: 30px;
            background-color: rgba(255, 255, 255, 0.9);
            border-radius: 20px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }
        
        h1 {
            color: #2c3e50;
            margin-bottom: 10px;
            font-family: "楷体";
            font-size: 3.4rem;
            text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1);
        }
        
        .subtitle {
            color: #7f8c8d;
            margin-bottom: 30px;
            font-size: 1.2rem;
        }

        .olympics-container {
            position: relative;
            width: 600px;
            height: 400px;
            margin: 24px;
            display: flex;
            justify-content: center;
            align-items: center;
            transform-style: preserve-3d;
        }
        
        /*奥运五环的CSS属性*/
        
        .ring {
            position: absolute;
            width: 200px;
            height: 200px;
            border-radius: 50%;
            border-width: 20px;
            border-style: solid;
            top: -20px;
            right: -20px;
        }
       
        /*504*/
        .blue {
            color: #0082c9;
            left: 0px;
            top: 0px;
            transform: rotateX(356deg); 
            transform-origin: center 75%;
        }
        .yellow {
            color: #fcb32e;
            top: 100px;
            left: 126px; /*240+6 - 120 */
            transform: rotateX(358deg); 
            transform-origin: center 25%;
        }
        .black {
            color:#000000;
            top: 0px;
            left: 252px; /*200 + 40 +12 */
        }
        .green {
            color: #30a751;
            top: 100px;
            left: 376px;/*504-6 - 120 */
            transform: rotateX(2deg); 
            transform-origin: center 25%;
        }
        
        .red {
            color: #ef314e;
            top: 0px;
            left: 504px; /*200 + 40 +20 */
            transform: rotateX(4deg); 
            transform-origin: center 75%;
        }



        /**/
        /* 奥运五环标志 */
        .olympic-symbol {
            font-size: 1.5rem;
            color: #2c3e50;
            margin-top: 20px;
            letter-spacing: 2px;
            font-weight: bold;
        }

        
        /* 环的颜色说明 */

        .blue-color { background-color: #0085C7; }
        .yellow-color { background-color: #F4C300; }
        .black-color { background-color: #000000; }
        .green-color { background-color: #009F3D; }
        .red-color { background-color: #DF0024; }

        .color-info {
            display: flex;
            justify-content: center;
            flex-wrap: wrap;
            gap: 15px;
            margin-top: 30px;
        }
        
        .color-item {
            display: flex;
            align-items: center;
            margin: 5px 10px;
        }
        
        .color-box {
            width: 20px;
            height: 20px;
            border-radius: 3px;
            margin-right: 8px;
        }
        
        .footer {
            margin-top: 30px;
            color: #7f8c8d;
            font-size: 0.9rem;
        }
    </style>
  </head>
  <body>
    <div class="container">
      <h1>奥运五环</h1>
      <p class="subtitle">使用纯HTML和CSS绘制 - 代表五大洲的团结</p>
      <div class="olympics-container">
        <div class="ring black"></div>
        <div class="ring blue"></div>
        <div class="ring yellow"></div>
        <div class="ring green"></div>
        <div class="ring red"></div>
      </div>

      <div class="olympic-symbol">OLYMPIC RINGS</div>

      <div class="color-info">
        <div class="color-item">
          <div class="color-box blue-color"></div>
          <span>蓝色 - 欧洲</span>
        </div>
        <div class="color-item">
          <div class="color-box yellow-color"></div>
          <span>黄色 - 亚洲</span>
        </div>
        <div class="color-item">
          <div class="color-box black-color"></div>
          <span>黑色 - 非洲</span>
        </div>
        <div class="color-item">
          <div class="color-box green-color"></div>
          <span>绿色 - 大洋洲</span>
        </div>
        <div class="color-item">
          <div class="color-box red-color"></div>
          <span>红色 - 美洲</span>
        </div>
      </div>

      <div class="footer">
        <p>奥运五环标志由皮埃尔·德·顾拜旦于1913年设计,五个环代表五大洲,六种颜色(含白色背景)代表当时所有国家的国旗颜色</p>
        <p style="margin-top: 10px;">少莫千华 | 纯CSS实现 | 无JavaScript | 响应式设计</p>
      </div>
    </div>
  </body>
</html>
相关推荐
前端snow8 小时前
ai agent --- postgreSQL 关系型数据库
前端
卷无止境9 小时前
ECharts:把数据变成故事的可视化利器
前端
Eric_见嘉9 小时前
在职前端 Skill 和 MCP 分享
前端·后端·agent
liangshanbo12159 小时前
面试题:如何优化 Webpack 的打包速度?
前端·webpack·node.js
wengad9 小时前
从 wangEditor 迁到 wangEditor-next
前端·javascript·vue.js
行者-全栈开发10 小时前
【前端/JS框架】CVE-2026-3854:GitHub Enterprise Server X-Stat注入XSS漏洞深度剖析与紧急修复指南
前端·javascript·github
计算机魔术师11 小时前
AMD砸82亿买下李飞飞,这次不卖芯片卖什么?
前端
hzxpaipai12 小时前
杭州企业官网怎么建设?从策划到上线的5步建站方法
运维·服务器·前端·网络
怕浪猫12 小时前
2026年金九银十,我面了22个前端
前端·javascript·面试
IT_陈寒12 小时前
Vue 这个响应式陷阱,我的头发都掉没了
前端·人工智能·后端