CSS3脉动甜甜圈
CSS3脉动甜甜圈
知识点分析:
水平,垂直居中
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
设置多个径向渐变,指定背景显示大小,以60*60的区域,重复显示径向渐变形成的图案。
background-image:
radial-gradient(#0fc 15%, transparent 16%),
radial-gradient(#ff0 15%, transparent 16%);
background-size: 60px 60px;
background-position: 0 0, 30px 30px;
html:
<div class="container"> <div class="donut__glazed"></div> <div class="donut__sprinkles"></div> <div class="donut__chocolate"></div> </div>
css:
<style> *{ margin: 0; padding: 0; box-sizing: border-box; } body{ width: 100vw; height: 100vh; background-color: #a2989d; display: flex; justify-content: center; align-items: center; } .container{ width: 100%; height: 50vh; display: flex; justify-content: center; align-items: center; } [class*=donut] { width: 25vw; height: 25vw; border-radius:50%; margin: 1rem; float: left; position: relative; } .donut__glazed{ background-color: #fff; border: 2vw solid #f5deb3; box-shadow: 0.5vw 0.5vw 0 rgba(0,0,0,0.1); } .donut__glazed::before{ content: ''; width: 5vw; height: 5vw; background-color: #a2988d; border: 2vw solid #f5deb3; border-radius: 50%; box-shadow: inset 0.5vw 0.5vw 0 rgba(0,0,0,0.1); position: absolute; top: 50%; left: 50%; transform: translateX(-50%) translateY(-50%); } .donut__sprinkles{ background-color: #ff748c; border: 2vw solid #f5deb3; box-shadow: 0.5vw 0.5vw 0 rgba(0,0,0,0.1); background-image: radial-gradient(#0fc 15%, transparent 16%), radial-gradient(#ff0 15%, transparent 16%); background-size: 60px 60px; background-position: 0 0, 30px 30px; } .donut__sprinkles::before{ content: ''; width: 5vw; height: 5vw; background-color: #a2988d; border: 2vw solid #f5deb3; border-radius: 50%; box-shadow: inset 0.5vw 0.5vw 0 rgba(0,0,0,0.1); position: absolute; top: 50%; left: 50%; transform: translateX(-50%) translateY(-50%); } .donut__chocolate{ background-color: #372411; border: 2vw solid #613e1e; box-shadow: 0.5vw 0.5vw 0 rgba(0,0,0,0.1); } .donut__chocolate::before{ content: ''; width: 5vw; height: 5vw; background-color: #a2988d; border: 2vw solid #613e1e; border-radius: 50%; box-shadow: inset 0.5vw 0.5vw 0 rgba(0,0,0,0.1); position: absolute; top: 50%; left: 50%; transform: translateX(-50%) translateY(-50%); } </style>
还没有留言,还不快点抢沙发?