成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

純 CSS 實現(xiàn)奧運五環(huán),環(huán)環(huán)相扣!

開發(fā) 前端
奧運五環(huán)是相互連接的,因此在視覺上會產(chǎn)生重疊效果,這也是實現(xiàn)五環(huán)最有挑戰(zhàn)性的部分。接下來,將利用 CSS 的偽元素,巧妙地實現(xiàn)環(huán)環(huán)相扣的效果!

2024 巴黎奧運會正如火如荼地進行,本文來使用 CSS 來畫一個奧運五環(huán)。奧運五環(huán)是相互連接的,因此在視覺上會產(chǎn)生重疊效果,這也是實現(xiàn)五環(huán)最有挑戰(zhàn)性的部分。接下來,將利用 CSS 的偽元素,巧妙地實現(xiàn)環(huán)環(huán)相扣的效果!

根據(jù)五環(huán)的位置特點,可以將中間的黑色環(huán)設置為 HTML 的父元素,而將其他顏色的環(huán)設置為子元素。這樣,其他環(huán)就可以相對于黑色環(huán)進行定位。整體的 HTML 結(jié)構(gòu)如下:

<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 邊框畫出黑環(huán)和其他四環(huán)的基本樣式:

.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;
}

接下來畫綠環(huán),它相對于黑環(huán)進行定位,向右向下移動,并且層級比黑環(huán)高:

.green {
  color: #30a751;
  top: 70px;
  right: -125px;
  z-index: 2;
}

此時的效果是這樣的,黑環(huán)的z-index為 1,綠環(huán)的z-index為 2:

而我們希望兩環(huán)右側(cè)的交車點處,黑環(huán)位于上方,這時就可以使用偽元素來實現(xiàn)。給黑環(huán)添加一個和它大小一樣的偽元素::after,并將其放在黑環(huán)的正上方,z-index為3。接著,將偽元素的右邊框設置為黑色,其他方向為透明,這樣就成功使黑環(huán)的右側(cè)看起來位于綠環(huán)上方了:

.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;
  }
}

效果如下:

這里我來向右移動一下這個偽元素的位置,來看看他的樣子:

到這你應該就明白了,這里只是視覺上的環(huán)環(huán)相扣,實際上,兩個環(huán)并不在同一層。

接下來畫紅環(huán)。由于綠環(huán)的z-index為2,所以紅環(huán)位于綠環(huán)下方:

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

效果如下:

此時只需按照上面的步驟,給紅環(huán)添加一個帶有紅色下邊框的偽元素即可:

.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;
  }
}

效果如下:

黃環(huán)和藍環(huán)同理,這里直接附上完整代碼:

.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;
    }
  }
}

最終效果如下:

責任編輯:姜華 來源: 前端充電寶
相關推薦

2022-07-12 14:53:58

區(qū)塊鏈元宇宙資本

2021-01-15 09:36:23

漏洞shellweb安全

2016-04-26 09:47:28

2015-05-18 16:37:57

華為華為HSR方案

2015-01-20 10:57:10

2017-06-16 10:03:09

互聯(lián)網(wǎng)

2018-10-17 14:50:08

2019-11-05 09:47:28

互聯(lián)網(wǎng)IT程序員

2025-03-17 12:18:42

2024-06-11 14:40:46

2012-02-16 10:49:09

2011-07-25 09:15:21

蘋果微軟喬布斯

2020-08-18 16:52:12

商業(yè)管理學

2021-10-19 22:23:47

CSSBeautiful按鈕

2024-08-29 08:13:58

2012-06-12 11:02:52

激光打印機行情

2015-09-14 16:57:30

4G+4G

2022-02-21 07:02:16

CSSbeautiful按鈕

2013-04-08 14:07:28

CSS
點贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 日韩成人免费视频 | 一区二区三区精品在线视频 | 亚洲精品在线观 | 精品久久久久久亚洲国产800 | 免费午夜视频在线观看 | 亚洲黄色av | 玖玖视频网 | 国产精品一区二区视频 | 国产乱码精品一区二区三区中文 | 欧美日本免费 | 久久久久久久久国产成人免费 | 午夜欧美| 欧美精品v国产精品v日韩精品 | 精品国产乱码久久久久久牛牛 | 日韩激情免费 | 免费一级做a爰片久久毛片潮喷 | 国产精品久久久久久久粉嫩 | 91大神在线资源观看无广告 | 欧美亚洲高清 | 久久久久欧美 | 日韩性在线| 毛片久久久 | 亚洲成人免费av | wwwxxx日本在线观看 | 3级毛片 | 欧美一区二区三区视频 | 中文字幕第三页 | 日韩国产中文字幕 | 久久人人国产 | 91精品在线看 | 亚洲成人免费 | 午夜电影网址 | 国产一区二区在线免费播放 | 黄色日批视频 | 亚洲 中文 欧美 日韩 在线观看 | a在线观看免费 | 99国产精品久久久久 | 久久亚洲一区二区三区四区 | 久久999| 国产在线观看一区二区三区 | 九色视频网站 |