[前端面试题_上机] 请用 CSS 写出一个棒棒糖

382 阅读1分钟

效果图

snipaste20220402_200033.jpg

思路:

利用CSS的重复的径向渐变属性实现: repeating-radial-gradient

具体代码落地

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<style>
  .box{
    position: relative;
  }
  .candy{
    position: absolute;
    width: 400px;
    height: 400px;
    background: repeating-radial-gradient(red,yellow 10%,green 15%);
    border-radius: 50%;
  }
  .bar{
    position: absolute;
    width: 15px;
    height: 300px;
    border-radius: 3px;
    margin-left: 188px;
    margin-top: 400px;
    background-color: #e9dab9;
  }
</style>
<body>
  <div class="box">
    <div class="candy"></div>
    <div class="bar"></div>
  </div>
</body>
</html>