[CSS] Create Complex Shapes with CSS Clip Path and Border Radiusc (border-radius & clip-path)

In this lesson, we explore creating the Egghead Shell with CSS. We explore how different properties allow us to create different shapes and how we can use our developer tools to adjust and tweak style values.

https://egghead.io/lessons/css-create-complex-shapes-with-css-clip-path-and-border-radius?pl=create-css-illustrations-b24c

复制代码
*,
*:before,
*:after {
  box-sizing: border-box;
}
:root {
  --bg: #ffd500;
  --shell: #fff;
  --shell-outline: #666;
  --size: 50;
  --unit: calc((var(--size) / 769) * 1vmin);
}

body {
  background-color: var(--bg);
  min-height: 100vh;
}

img {
  opacity: 0.5;
}

.egg {
  background-color: hsla(0, 100%, 50%, 0.2);
}

img,
.egg {
  height: calc(769 * var(--unit));
  width: calc(742 * var(--unit));
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.shell {
  height: 95%;
  width: 74%;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.shell__piece--top {
  height: 108%;
  width: 106%;
  border-radius: 50% 50% 0 0 / 85% 85% 0 0;
  top: 0;
  clip-path: inset(0 0 70% 0);
}

.shell__piece--middle {
  height: 100%;
  width: 98%;
  border-radius: 50% 50% 0 0 / 85% 85% 0 0;
  clip-path: inset(32% 0 40% 0);
}

.shell__piece--bottom {
  bottom: 0;
  border-radius: 50% / 62% 62% 38% 38%;
  width: 100%;
  height: 100%;
  clip-path: inset(58% 0 0 0);
}

.shell__piece {
  background-color: var(--shell);
  border: calc(26 * var(--unit)) solid var(--shell-outline);
  position: absolute;
  left: 50%;
  transform: translate(-50%, 0);
}
复制代码

 

border-radius:

border-radius: 50% 50% 0 0 / 85% 85% 0 0;

first (50% + 85%)

x: top-left, move right 50%

y: top-left, move down 85%

 

second (50% + 85%)

x: top-right, move left 50%

y: top-right, move down 85%

 

first and second (0 0)

no changes

 

clip-path:

Image:

before:

after clip:

clip-path: inset(87% 45% 5% 46%);

 

posted @   Zhentiw  阅读(145)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2018-08-10 [Algorithms] Determine if a string is a palindrome
2018-08-10 [Algorithm] Determine if two strings are an anagram
2017-08-10 [D3] Build a Column Chart with D3 v4
2016-08-10 [Practical Git] Format commit history with git log arguments
2016-08-10 [Practical Git] Navigate git command pager output with Unix less commands
2016-08-10 [Practical Git] Switching between current branch and last checkout branch
2014-08-10 [Javascript] Prototype 2 Object.create()
点击右上角即可分享
微信分享提示