snippetcssTip
Create shapes using CSS
Viewed 0 times
usingshapescreatecss
Problem
CSS can be used to create various shapes like circles, triangles, and squares. While this technique is slowly falling out of favor, it can sometimes be worth using for simple shapes, instead of using SVG or images.
https://codepen.io/chalarangelo/pen/gOJOwwo
A simple CSS square can be created by setting the
Using the
A triangle can be created by using three borders. The
https://codepen.io/chalarangelo/pen/gOJOwwo
A simple CSS square can be created by setting the
width and height to the same value. Similarly, a rectangle can be created by setting the width and height to different values.Using the
border-radius property, a circle can be created by setting it to 50%. The width and height must be the same to create a circle. Subsequently, an ellipse can be created by providing two values for the border-radius and setting the width and height to different values.A triangle can be created by using three borders. The
border-width should be the same for all borders, and the opposite side of where the triangle points towards should have the desired border-color. The adjacent borders should have a border-color of transparent.Solution
<div class="square"></div>
<div class="rectangle"></div>A simple CSS square can be created by setting the
width and height to the same value. Similarly, a rectangle can be created by setting the width and height to different values.Using the
border-radius property, a circle can be created by setting it to 50%. The width and height must be the same to create a circle. Subsequently, an ellipse can be created by providing two values for the border-radius and setting the width and height to different values.A triangle can be created by using three borders. The
border-width should be the same for all borders, and the opposite side of where the triangle points towards should have the desired border-color. The adjacent borders should have a border-color of transparent.Code Snippets
<div class="square"></div>
<div class="rectangle"></div>.square {
width: 64px;
height: 64px;
background: #5394fd;
}
.rectangle {
width: 128px;
height: 64px;
background: #5394fd;
}<div class="circle"></div>
<div class="ellipse"></div>Context
From 30-seconds-of-code: shapes
Revisions (0)
No revisions yet.