首页 > 其他分享 >css手撕奥运五环

css手撕奥运五环

时间:2024-08-05 09:57:04浏览次数:11  
标签:right width solid 五环 20px border 奥运 css 200px

巴黎奥运会正如火如荼地进行,本文来使用 CSS 来画一个奥运五环。奥运五环是相互连接的,因此在视觉上会产生重叠效果,这也是实现五环最有挑战性的部分。接下来,将利用 CSS 的伪元素,巧妙地实现环环相扣的效果!

 根据五环的位置特点,可以将中间的黑色环设置为 HTML 的父元素,而将其他颜色的环设置为子元素。这样,其他环就可以相对于黑色环进行定位。整体的 HTML 结构如下:

<div class="black">
  <div class="ring blue"></div>
  <div class="ring yellow"></div>
  <div class="ring green"></div>
  <div class="ring red"></div>
</div>

首先,用 CSS 边框画出黑环和其他四环的基本样式:

.black {
  position: relative;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  border-width: 20px;
  border-style: solid;
}

.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: -125px;
  z-index: 2;
}

此时的效果是这样的,黑环的z-index为 1,绿环的z-index为 2:

 

而我们希望两环右侧的交车点处,黑环位于上方,这时就可以使用伪元素来实现。给黑环添加一个和它大小一样的伪元素::after,并将其放在黑环的正上方,z-index3。接着,将伪元素的右边框设置为黑色,其他方向为透明,这样就成功使黑环的右侧看起来位于绿环上方了:

 
.black {
  position: relative;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  border-width: 20px;
  border-style: solid;

  &::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;
  }
}

 这里我来向右移动一下这个伪元素的位置,来看看他的样子:

 

 

到这你应该就明白了,这里只是视觉上的环环相扣,实际上,两个环并不在同一层。

接下来画红环。由于绿环的z-index2,所以红环位于绿环下方:

.red {
  color: #ef314e;
  right: -230px;
}

 

.red {
  color: #ef314e;
  right: -230px;

  &::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;
  }
}

整体代码如下:

 
.black {
  position: relative;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  border-width: 20px;
  border-style: solid;

  &::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;
  }

  &::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;
  }

  .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: -125px;
    z-index: 2;
  }

  .red {
    color: #ef314e;
    right: -230px;

    &::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: -125px;
  }

  .blue {
    color: #0082c9;
    left: -230px;

    &::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;
    }
  }
}

最终效果如下:

 感谢阅读,记着点个赞哦,在此,谢谢各位啦!!!

 

标签:right,width,solid,五环,20px,border,奥运,css,200px
From: https://www.cnblogs.com/houxianzhou/p/18342662

相关文章

  • 3.初识CSS与文本背景样式
    目录1.上节回顾2.CSS定义3.CSS选择器4.CSS样式的三种写法5.div盒子标签(division)6.文本样式(font)7.背景样式(background)1.上节回顾超链接a标签:<ahref='地址'>超链接文本</a> 也可以用id属性来超链接文本里面的内容<imgsrc='图片地址'alt='图片描述'>列表分为有序,无序,自定......
  • html+css 实现hover边框彩色流动
    前言:哈喽,大家好,今天给大家分享html+css绚丽效果!并提供具体代码帮助大家深入理解,彻底掌握!创作不易,如果能帮助到大家或者给大家一些灵感和启发,欢迎收藏+关注哦......
  • CSS简单笔记
    1.CSS简介1.1HTML的局限性特别单纯,只关注内容的语义,只能做出简洁的网站页面。1.2CSS—网页的美容师CSS是层叠样式表(CascadingStyleSheets)的简称,有时我们会称之为CSS样式表或级联样式表。CSS也是一种标记语言,主要用来设置HTML页面中的文本内容(字体、大小、对齐方式等)、图......
  • 【Dash】使用 HTML 和 CSS 创建图表
    一、StylingYourAppTheexamplesintheprevioussectionusedDashHTMLComponentstobuildasimpleapplayout,butyoucanstyleyourapptolookmoreprofessional.Thissectionwillgiveabriefoverviewofthemultipletoolsthatyoucanusetoenhanc......
  • 手把手使用 SVG + CSS 实现渐变进度环效果
    效果轨道使用svg画个轨道<svgviewBox="00100100"><circlecx="50"cy="50"r="40"fill="none"stroke-width="10"stroke="#333"></circle></svg>简单的说,就是使用ci......
  • 奥运会Ⅰ--Google大模型 - 效率的伟大胜利
    不惜一切代价正如我们多次提到的,LLM最看重的是规模。这是因为随着参数数量的增加,这些模型会开发出新功能。因此,这些模型的每一代新模型通常都比之前的模型大得多,其中GPT-4的大小是GPT-3的十倍,而据传GPT-5比GPT-4大30倍(如果我们使用微软首席技术官KevinScott对......
  • 奥运会Ⅱ---谁会先抢走你的工作?
    DevinAI与MicrosoftAutoDev,谁会先抢走你的工作?软件开发领域正处于一场革命的风口浪尖。DevinAI和MicrosoftAutoDev的出现,是人工智能编码领域的两项突破性进步,有望重塑软件构建方式。但是,在如此截然不同的方法中,哪一种占主导地位?让我们深入研究Devin和AutoDev的复杂......
  • 首次AI奥运会 | 这次科技风暴,你跟上了吗?
    近日,首届AI奥运会(第33届夏季奥林匹克运动会)赛事正酣,目前中国队已斩获10余项赛事项目金牌。赛思分布式数据中心时钟系统解决方案助力阿里云AI技术征战国际,在巴黎奥运会上大放异彩。阿里云:把奥运会搬上“云端”,创造多项首次!2024年7月26日至8月11日,第33届夏季奥林匹克运动会......
  • [CSS] max-content, min-content, fit-content
    max-contenthttps://developer.mozilla.org/en-US/docs/Web/CSS/max-contentThe max-content sizingkeywordrepresentsthemaximum intrinsicsize ofthecontent.Fortextcontentthismeansthatthecontentwillnotwrapatallevenifitcausesoverflows.......
  • HTML5+CSS3笔记(Xmind格式):第一天
    Xmind鸟瞰图:文字总结:1.新增语义化标签:-header:定义文档的页眉,用来表示页面的头部。-nav:定义导航链接的部分nav元素代表页面中的导航,其中的导航元素链接到其他页面或当前页面的其他部分。-main:主体信息-aside:侧边栏-article:article元素表示文档、页面或应用程......