css实战中,怎么制作这样的一个环环相扣的五个环呢? 绘制五个圈圈很容易,关键是要环环相扣,尤其要注意环环相交部分的处理。这里要用到transform-style: preserve-3d; 和 transform: rotateY( 1deg ) 等关键的css技术。
效果图
源代码
/*
* @Author: 大剑师兰特(xiaozhuanlan),还是大剑师兰特(CSDN)
* @此源代码版权归大剑师兰特所有,可供学习或商业项目中借鉴,未经授权,不得重复地发表到博客、论坛,问答,git等公共空间或网站中。
* @Email: 2909222303@qq.com
* @weixin: gis-dajianshi
* @First published in CSDN
* @First published time: 2023-11-11
*/
<template>
<div class="container">
<div class="top">
<h3>绘制一个环环相扣的五环</h3>
<div class="author">大剑师兰特, 还是大剑师兰特,gis-dajianshi</div>
</div>
<div class="dajianshi-rings">
<div class="ring"></div>
<div class="ring"></div>
<div class="ring"></div>
<div class="ring"></div>
<div class="ring"></div>
</div>
</div>
</template>
<style scoped>
.container {
width: 1000px;
height: 580px;
margin: 50px auto;
border: 1px solid green;
position: relative;
}
.top {
margin: 0 auto 0px;
padding: 10px 0;
background: plum;
color: #fff;
}
.dajianshi-rings {
width: 350px;
height: 350px;
position: relative;
margin: 100px auto 0;
transform-style: preserve-3d;
}
.ring {
position: absolute;
border: 12px solid;
width: 100px;
height: 100px;
border-radius: 50%;
}
.ring:nth-child(1) {
border-color: red;
top: 0;
left: 0;
transform: rotateY( 1deg )/*3D效果,以y轴旋转*/
}
.ring:nth-child(2) {
border-color: black;
top: 0px;
left: 130px;
transform: rotateY( 1deg )
}
.ring:nth-child(3) {
border-color: red;
top: 0px;
left: 260px;
transform: rotateY( 1deg )
}
.ring:nth-child(4) {
border-color: yellow;
top: 60px;
left: 60px;
transform: rotateY( -1deg )
}
.ring:nth-child(5) {
border-color: yellow;
top: 60px;
left: 190px;
transform: rotateY( -1deg )
}
</style>