惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threatpost
博客园 - 叶小钗
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
D
DataBreaches.Net
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
N
Netflix TechBlog - Medium
Microsoft Azure Blog
Microsoft Azure Blog
Microsoft Security Blog
Microsoft Security Blog
B
Blog
U
Unit 42
有赞技术团队
有赞技术团队
博客园 - 聂微东
GbyAI
GbyAI
宝玉的分享
宝玉的分享
F
Full Disclosure
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MyScale Blog
MyScale Blog
Jina AI
Jina AI
Martin Fowler
Martin Fowler
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Docker
P
Proofpoint News Feed
A
About on SuperTechFans
I
InfoQ
博客园 - 【当耐特】
C
Check Point Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
T
Threat Research - Cisco Blogs
Y
Y Combinator Blog
Project Zero
Project Zero
WordPress大学
WordPress大学
小众软件
小众软件
AWS News Blog
AWS News Blog
博客园 - 司徒正美
T
The Exploit Database - CXSecurity.com
L
LINUX DO - 热门话题
I
Intezer
Engineering at Meta
Engineering at Meta
C
CXSECURITY Database RSS Feed - CXSecurity.com
J
Java Code Geeks
T
Tenable Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Last Week in AI
Last Week in AI
C
CERT Recently Published Vulnerability Notes

CSS Articles by Temani Afif

Get Ready For the Powerful CSS border-shape Property! | CSS-Tricks Let’s Play With Gap Decorations! How to Control Infinite CSS Animations (Part 2 of 2) How to Control Infinite CSS Animations (Part 1 of 2) Two Circles, One Arrow, and Anchor Positioning Making a Responsive Pyramidal Grid With Modern CSS | CSS-Tricks How to Create a CSS-only Elastic Text Effect Making Complex CSS Shapes Using shape() | CSS-Tricks Responsive Hexagon Grid Using Modern CSS | CSS-Tricks Responsive List of Avatars Using Modern CSS (Part 2) | CSS-Tricks Responsive List of Avatars Using Modern CSS (Part 1) | CSS-Tricks Perfectly Pointed Tooltips: To The Corners Perfectly Pointed Tooltips: All Four Sides Perfectly Pointed Tooltips: A Foundation Sequential linear() Animation With N Elements | CSS-Tricks Infinite Marquee Animation using Modern CSS Better CSS Shapes Using shape() — Part 4: Close and Move | CSS-Tricks Drawing CSS Shapes using corner-shape Better CSS Shapes Using shape() — Part 3: Curves | CSS-Tricks Better CSS Shapes Using shape() — Part 2: More on Arcs | CSS-Tricks Better CSS Shapes Using shape() — Part 1: Lines and Arcs | CSS-Tricks Creating Blob Shapes using clip-path: shape() Creating Flower Shapes using clip-path: shape() Custom progress element using the attr() function A CSS-Only Star Rating Component and More! (Part 2) | CSS-Tricks A CSS-Only Star Rating Component and More! (Part 1) | CSS-Tricks How to Create Wavy Boxes Using CSS Full-Bleed Layout with Modern CSS Fancy Menu Navigation Using Anchor Positioning | CSS-Tricks How to Create a Zig-Zag Box Using CSS How to Create Zig-Zag CSS Loaders Using One Element Custom Progress Element Using Anchor Positioning & Scroll-Driven Animations How to Create Filling CSS Loaders Using One Element How to Create Curved-Edge and Rounded-Edge Shapes Using CSS CSS Tricks That Use Only One Gradient | CSS-Tricks How to create Shapes with Inner Curves using CSS Mask Custom Range Slider Using Anchor Positioning & Scroll-Driven Animations How to Get the Width/Height of Any Element in Only CSS How Keyboard Navigation Works in a CSS Game How To Create Cut-Out Shapes using The clip-path property The Modern Guide For Making CSS Shapes — Smashing Magazine css-shape.com: The Ultimate Collection of CSS-only Shapes ⚡️ Sliding 3D Image Frames In CSS — Smashing Magazine CSS Tricks To Master The clip-path Property Creating Wavy Circles with Fancy Animations in CSS Modern CSS Tooltips And Speech Bubbles (Part 2) — Smashing Magazine Do you need a Tooltip or a Speech Bubble? I have created 100 using CSS 😲 Modern CSS Tooltips And Speech Bubbles (Part 1) — Smashing Magazine Creating Flower Shapes using CSS Mask & Trigonometric Functions CSS Shapes: The Triangle The Complex But Awesome CSS border-image Property — Smashing Magazine CSS Tricks to add 3D Effects to your Text CSS Responsive Multi-Line Ribbon Shapes (Part 2) — Smashing Magazine CSS Responsive Multi-Line Ribbon Shapes (Part 1) — Smashing Magazine I have made 100+ CSS-only Ribbon Shapes | The Perfect Collection 🎀 How to create a CSS-only infinite scroll animation Re-Creating The Pop-Out Hover Effect With Modern CSS (Part 2) — Smashing Magazine Re-Creating The Pop-Out Hover Effect With Modern CSS (Part 1) — Smashing Magazine How to Create CSS Ribbon Shapes with a Single Element CSS Shapes: The Ribbon Revealing Images With CSS Mask Animations — Smashing Magazine css-loaders.com: The Biggest Collection of Loading Animations (more than 500 🤯) How To Define An Array Of Colors With CSS — Smashing Magazine CSS effects on images II Shines, Perspective, And Rotations: Fancy CSS 3D Effects For Images — Smashing Magazine What's your Lucky CSS Pattern? Check It Now! How to Add a CSS Reveal Animation to Your Images Modern Layouts using CSS Grid I created 100+ unique CSS patterns | The best collection 🤩 How to Create a Custom Range Slider Using CSS CSS Shapes: The Heart A Text Reveal Animation using CSS CSS Tip: learn CSS the easy way! How to build a CSS-only accordion How to create Breadcrumb Navigation with CSS Different Ways to Get CSS Gradient Shadows | CSS-Tricks A CSS-only responsive Stepper component A Fancy Hover Effect For Your Avatar | CSS-Tricks How to make a zoom effect using CSS Creating a Custom Cursor using CSS CSS Infinite 3D Sliders | CSS-Tricks CSS Infinite Slider Flipping Through Polaroid Images | CSS-Tricks How to create a responsive sidebar menu using CSS CSS Infinite and Circular Rotating Image Slider | CSS-Tricks Making Static Noise From a Weird CSS Gradient Bug | CSS-Tricks CSS Grid and Custom Shapes, Part 3 | CSS-Tricks Fancy Image Decorations: Outlines and Complex Animations | CSS-Tricks Fancy Image Decorations: Masks and Advanced Hover Effects | CSS-Tricks Fancy Image Decorations: Single Element Magic | CSS-Tricks How to create an infinite image slider using CSS How to Create Wavy Shapes & Patterns in CSS | CSS-Tricks How I Made a Pure CSS Puzzle Game | CSS-Tricks How to create a Tooltip/Speech Bubble using CSS CSS Grid and Custom Shapes, Part 2 | CSS-Tricks CSS Grid and Custom Shapes, Part 1 | CSS-Tricks Zooming Images in a Grid Layout | CSS-Tricks How to create a CSS-only loader with one element Exploring CSS Grid’s Implicit Grid and Auto-Placement Powers | CSS-Tricks How to create background pattern using CSS & conic-gradient Single Element Loaders: The Bars | CSS-Tricks
CSS Shapes: Polygon & Starburst
2023-05-06 · via CSS Articles by Temani Afif

CSS Shapes: Polygon & Starburst

Written on by Temani AfifWeb Developer

Estimated read time 5 minutes

In this article, we are going to build CSS Shapes! We will use clip-path combined with some math to generate polygon and starburst shapes.

CSS Shapes: polygon & starburst

I said “generate” because we are going to use generators to get the different shapes. Some shapes are complex and writing the code by hand is not an easy task so I have built online generators to help you get the different shapes by simply adjusting a few variables.

This said it’s also good to understand the logic behind the generated code.

CSS Polygon Shapes

Let’s start with polygons and the first online generator: css-generators.com/polygon-shape

All you have to do is to define the number of sides and the rotation. You also have the ability to create the border-only version and control the border thickness as well.

Here is a figure to illustrate the clip-path points of a polygon shape

Overview of the clip-path polygon

We first consider a square element:

.box {
  width: 200px;
  aspect-ratio: 1;
}

Then, each point of the clip-path will be defined as follow:

x : 50% + 50%*cos(angle + (i * 360deg)/sides);
y : 50% + 50%*sin(angle + (i * 360deg)/sides);

sides is the variable that controls the number of sides. angle is the rotation. And i is the index of each point. If you are good at geometry you already noticed that we are evenly placing the points on a circle. The radius of the circle is half the element’s width and its center is the center of the element

Overview of the clip-path polygon

Even if the logic is easy, it would be tedious to write all the code by hand especially if the number of sides is big. With the online generator, you get the code in no time.

Here are a few common CSS shapes you can get:

Triangle

clip-path: polygon(100% 50%,25.00% 93.30%,25% 6.70%);
/* OR */
clip-path: polygon(93.30% 75%,6.70% 75.00%,50% 0%);

Rhombus

clip-path: polygon(100% 50%,50% 100%,0% 50%,50% 0.00%);

Hexagon

clip-path: polygon(100% 50%,75% 93.30%,25% 93.30%,0% 50%,25% 6.70%,75% 6.70%);
/* OR */
clip-path: polygon(93.30% 75%,50% 100%,6.70% 75%,6.70% 25%,50% 0%,93.30% 25%);

Worth noting that, since we are using clip-path, we can have any kind of background and also apply the shape to an image.

The logic for the border-only version is similar but we will need more points to define the shape:

Overview of the border-only polygon

The outer points are the same as previously. The inner points will get placed considering another circle with a smaller radius.

x = 50% + (50% - border)*cos(angle + (i * 360deg)/sides);
y = 50% + (50% - border)*sin(angle + (i * 360deg)/sides);

The border variable is what controls the thickness.

Here we can clearly see that a generator is a life save because we have twice the number of points and it’s not easy to write all them manually. Not to mention, that the order of the points is important to get the final shape but no need to worry about it.

Here are a few examples:

50%

💰 EXTRA 50% OFF ALL VERPEX YEARLY MANAGED CLOUD SERVER PLANS

with the discount code

SERVERS-SALE

CSS Starburst Shapes

Let’s move to the next generator. This time we will create starburst shapes (also called spiky shapes): css-generators.com/starburst-shape

Similar to the previous generator, all you have to do is to adjust a few variables and get the code. Here is a figure to illustrate the shape:

Overview of the starburst shape

We are still placing points on circles but with a different logic. We alternate the placement: One point on the bigger circle then another point on the smaller circle.

x : 50% + 50%*cos(angle + (i * 360deg)/spikes);
y : 50% + 50%*sin(angle + (i * 360deg)/spikes);

Then:

x : 50% + (50% - size)*cos(angle + (i * 360deg + 180deg)/spikes);
y : 50% + (50% - size)*sin(angle + (i * 360deg + 180deg)/spikes);

Note how between the outer and inner points we have a shift equal to 180deg/spikes and a difference of distance equal to size.

What about the border-only version? we will keep adding more points?!

Yes! The number of points will keep increasing and the complexity of the code as well but you don’t need to worry about that because the online generator will do the job for you.

Here is how it looks for the border-only version

Overview of the border-only starburst shape

We logically have twice the number of points and four circles to use to place the different points. I won’t bother with the formula for this one but the logic is pretty similar to what we did with the border-only polygon shape. We first place the outer points then the inner points will use the same formula with a smaller radius.

Let’s not forget that we can create a Star shape using that generator:\

It is worth noting that if you make the size variable equal to 0 the Starburst shape will be a Polygon shape. So a starburst shape can be seen as a polygon where we move half of its points to be closer to the center. Geometry is fun!

from polygon to starburst

90%

💰 90% OFF YOUR FIRST MONTH WITH ALL VERPEX CLOUD HOSTING PLANS

with the discount code

AWESOME

Conclusion

In addition to the online generators, now you know the secret behind the code for creating Polygon and Starburst shapes. With a few clicks, you can easily generate a triangle, a hexagon, a rhombus, a star, etc. So many different CSS shapes.

Bookmark these two links and show me in the comment section the shapes you have created and how did you integrate them into your website.

If you want to learn more about clip-path you can refer to my article "CSS Tricks To Master The clip-path Property"

Frequently Asked Questions

Temani Afif

Temani Afif is an expert web developer, a content creator, and a CSS addict. He is the mastermind behind CSS Loaders, CSS Generators, CSS Tip and many other CSS-related websites.

View more posts by Temani Afif