CSS 中的 Luigi
路易基总是屈居次席,但他值得被爱。受这张精彩的运球插画的启发,看看我如何用 CSS 用一系列椭圆形重新绘制路易基。
本文最初发表于codinhood.com
路易吉的帽子 CSS
剥去帽子上的所有细节,最终呈现出一个底部更厚的胖蛋形状。我们可以在 CSS 中通过为 属性提供 8 个值来创建此形状border-radius
,这使我们能够自定义每个角的高度和宽度border-radius
。查看W3C 关于 border-radius 的规范,了解更多关于此技术的信息。
<div class="Luigi">
<div class="Luigi__hat"></div>
</div>
.Luigi {
height: 400px;
width: 400px;
position: relative;
}
.Luigi__hat {
margin-left: calc(50% - 125px);
height: 250px;
width: 250px;
background: #1ca42f;
border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
position: relative;
}
Luigi 帽子标志 CSS
大写字母“L”的标志比它看起来要复杂一些,因为“L”的茎和枝的大小不同,一端较粗,而且略微旋转。为了让它看起来正确,我们进行了多次迭代和伪元素设计。
<div class="Luigi__hat">
<div class="Luigi__logo">
<div class="Luigi__stem"></div>
<div class="Luigi__branch"></div>
</div>
</div>
.Luigi__logo {
background: white;
width: 80px;
height: 80px;
border-radius: 100%;
left: calc(50% - 40px);
top: 25px;
position: absolute;
}
.Luigi__stem {
position: absolute;
top: 8px;
left: calc(50% - 15px);
height: 45px;
width: 16px;
background: #1ca42f;
border-radius: 1px;
}
.Luigi__stem::before {
content: "";
position: absolute;
height: 2px;
width: 12px;
top: -1px;
background: white;
transform: rotate(-5deg);
}
.Luigi__stem::after {
content: "";
position: absolute;
height: 40px;
width: 5px;
top: 0px;
left: 12.33px;
background: white;
transform: rotate(3deg);
}
.Luigi__branch {
position: absolute;
top: 45px;
left: 25px;
height: 11px;
width: 33px;
background: #1ca42f;
border-radius: 1px;
}
.Luigi__branch::before {
content: "";
position: absolute;
height: 3px;
width: 20px;
top: -2px;
left: 11.5px;
background: white;
transform: rotate(-5deg);
}
路易吉的帽子 CSS
帽子呈椭圆形,内侧椭圆颜色较深,营造出一种置身于帽子“内部”的错觉。这种错觉需要先将颜色放入帽子内部才能真正实现,但它应该与标志的白色部分重叠,以营造帽子的深度感。
<div class="Luigi__hat">
<div class="Luigi__logo">
<div class="Luigi__stem"></div>
<div class="Luigi__branch"></div>
</div>
<div class="Luigi__cap "></div>
</div>
.Luigi__cap {
position: absolute;
left: calc(50% - 85px);
top: 105px;
width: 170px;
height: 140px;
border-radius: 50%;
background: #025a10;
box-shadow: 0 -0.8em 0 0 #32b744;
}
路易吉的耳朵 CSS
路易吉的耳朵是椭圆形,border-radius
两侧各有特定的“”。耳朵靠近脸部的一侧不太圆,而耳朵外侧则更圆。我们可以使用border-radius
简写来定义椭圆形的每个角,以创建如下所示的形状。
<div class="Luigi">
<div class="Luigi__ear Luigi__ear--left"></div>
<div class="Luigi__ear Luigi__ear--right"></div>
...
</div>
.Luigi__ear {
background: #f8ccb3;
width: 50px;
height: 75px;
left: 80px;
top: 200px;
position: absolute;
border-radius: 50% 40% 40% 90%;
overflow: hidden;
}
.Luigi__ear--right {
left: 270px;
border-radius: 40% 50% 90% 40%;
}
.Luigi__ear--left::after {
content: "";
height: 60px;
width: 40px;
background: #e5b69b;
position: absolute;
right: -5px;
top: 5px;
border-radius: 50% 40% 40% 90%;
}
.Luigi__ear--right::after {
content: "";
height: 60px;
width: 40px;
background: #e5b69b;
position: absolute;
left: -5px;
top: 5px;
border-radius: 40% 50% 90% 40%;
}
路易吉的脸 CSS
希望你现在意识到我可能会用椭圆形来画路易吉的脸,如果是这样,你完全正确。我们可以通过添加一条不混合的border-radius
垂直线来创建五点钟方向的阴影。linear-gradient
<div class="Luigi">
...
<div class="Luigi__face"></div>
</div>
.Luigi__face {
background-image: linear-gradient(to bottom, #f8ccb3 50%, #ecb494 50%);
height: 250px;
width: 175px;
position: absolute;
top: 115px;
left: calc(50% - 87.5px);
border-radius: 100%;
z-index: 1;
}
路易吉的眉毛 CSS
路易吉的眉毛本质上是粗圆弧,两侧逐渐变细。我们可以在 CSS 中创建这种效果,首先在 CSS 中创建一个规则的圆圈:
然后创建另一个与第一个圆重叠的圆:
然后改变重叠的圆圈以匹配背景的颜色,以产生“剪切”原始圆圈的错觉:
与第一个圆圈重叠的第二个圆圈是用::after
伪元素创建的,但您可以轻松地创建另一个完整元素。
<div class="Luigi__eyebrow"></div>
<div class="Luigi__eyebrow Luigi__eyebrow--right"></div>
.Luigi__eyebrow {
width: 40px;
height: 43px;
border-radius: 100%;
background: #2e0400;
position: absolute;
left: 37px;
top: 10px;
transform: rotate(10deg);
}
.Luigi__eyebrow::after {
content: "";
background: #f8ccb3;
position: absolute;
bottom: -10px;
left: 3px;
height: 40px;
width: 45px;
border-radius: 100%;
}
.Luigi__eyebrow--right {
left: 97px;
transform: rotate(-10deg);
}
.Luigi__eyebrow--right::after {
right: 4px;
left: auto;
}
路易吉的眼睛 CSS
眼睛实际上只是嵌套的椭圆形(看到图案了吗?),在特定位置具有不同的颜色。
<div class="Luigi__eye">
<div class="Luigi__iris">
<div class="Luigi__pupil"></div>
</div>
</div>
<div class="Luigi__eye Luigi__eye--right">
<div class="Luigi__iris Luigi__iris--right ">
<div class="Luigi__pupil Luigi__pupil--right"></div>
</div>
</div>
.Luigi__eye {
background: white;
height: 70px;
width: 45px;
border-radius: 100%;
position: absolute;
left: 35px;
top: 40px;
overflow: hidden;
z-index: 2;
}
.Luigi__eye--right {
left: 95px;
}
.Luigi__iris {
width: 35px;
height: 55px;
background: #2ba7d1;
border-radius: 100%;
right: -2px;
bottom: 7px;
position: absolute;
}
.Luigi__iris--right {
left: -2px;
right: auto;
}
.Luigi__pupil {
width: 23px;
height: 40px;
background: black;
border-radius: 100%;
right: 4px;
bottom: 7px;
position: absolute;
}
.Luigi__pupil::before {
content: "";
position: absolute;
background: white;
height: 10px;
width: 10px;
border-radius: 100%;
left: 5px;
top: 5px;
}
.Luigi__pupil--right {
right: auto;
left: 4px;
}
路易吉的鼻子 CSS
路易吉的鼻子和这幅图中其他元素一样,呈椭圆形,border-radius
两侧的数值略有不同。将鼻子放置在眼睛上方,也能营造出一定的深度。
<div class="Luigi">
...
<div class="Luigi__nose"></div>
...
</div>
.Luigi__nose {
width: 84px;
height: 84px;
border-radius: 50% 50% 60% 60%;
background: #f6b996;
position: absolute;
left: calc(50% - 42px);
top: 86px;
z-index: 3;
}
路易吉的胡子 CSS
现在我们来谈谈脸部最重要的部分:胡子。胡子是整个形象的点睛之笔,所以处理好它至关重要。我们先画一个椭圆:
然后我们将使用多个在主椭圆形的两侧创建另外两个大椭圆形box-shadows
,查看图像以查看位置。
box-shadow: -2.25em 1em 0 red, 2.25em 1em 0 blue;
蓝色和红色只是占位符,方便你更好地区分形状。接下来,我们将创建另一个椭圆,它横跨顶部的三个椭圆。这个椭圆的颜色与路易吉的皮肤相同,而另外两个box-shadow
椭圆则改为胡须的颜色。
顶部的椭圆形将与路易吉鼻子两侧的皮肤融为一体,营造出一种剪掉椭圆的视觉效果,类似于他的眉毛。最后,我们需要将胡子放在鼻子下方、下巴上方。
<div class="Luigi__mustache"></div>
.Luigi__mustache {
position: absolute;
top: 73px;
left: calc(50% - 55px);
height: 96px;
width: 110px;
border-radius: 50%;
background: #2e0400;
box-shadow: -2.25em 1em 0 #2e0400, 2.25em 1em 0 #2e0400;
}
.Luigi__mustache::after {
content: "";
position: absolute;
top: 0em;
left: calc(50% - 85px);
height: 60px;
width: 170px;
border-radius: 50%;
background: #f8ccb3;
}
如果您喜欢这个 CSS 演示,您可能还会喜欢使用 CSS 绘制并制作 Bender 的脸部动画或使用 CSS 制作章鱼游泳动画。
文章来源:https://dev.to/codypearce/luigi-css-3667