Skip to content

Commit

Permalink
Combine shapes snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
Chalarangelo committed May 9, 2024
1 parent d57c3db commit 5385769
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 55 deletions.
6 changes: 6 additions & 0 deletions content/redirects.yaml
Expand Up @@ -2905,3 +2905,9 @@
- from: /css/s/checkerboard-pattern
to: /css/s/10-css-background-patterns
status: 301!
- from: /css/s/circle
to: /css/s/shapes
status: 301!
- from: /css/s/triangle
to: /css/s/shapes
status: 301!
26 changes: 0 additions & 26 deletions content/snippets/css/s/circle.md

This file was deleted.

108 changes: 108 additions & 0 deletions content/snippets/css/s/shapes.md
@@ -0,0 +1,108 @@
---
title: Create shapes using CSS
shortTitle: Shapes
type: story
language: css
tags: [visual]
cover: oven-paddle
excerpt: Use CSS to create various shapes like circles, triangles, and squares.
dateModified: 2024-05-08
---

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

## Square & Rectangle

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.

```html
<div class="square"></div>
<div class="rectangle"></div>
```

```css
.square {
width: 64px;
height: 64px;
background: #5394fd;
}

.rectangle {
width: 128px;
height: 64px;
background: #5394fd;
}
```

## Circle & Ellipse

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.

```html
<div class="circle"></div>
<div class="ellipse"></div>
```

```css
.circle {
width: 64px;
height: 64px;
border-radius: 50%;
background: #5394fd;
}

.ellipse {
width: 128px;
height: 64px;
border-radius: 64px / 32px;
background: #5394fd;
}
```

## Triangles

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`.

```html
<div class="triangle-down"></div>
<div class="triangle-up"></div>
<div class="triangle-left"></div>
<div class="triangle-right"></div>
```

```css
.triangle-down {
width: 0;
height: 0;
border-top: 32px solid #5394fd;
border-left: 32px solid transparent;
border-right: 32px solid transparent;
}

.triangle-up {
width: 0;
height: 0;
border-bottom: 32px solid #5394fd;
border-left: 32px solid transparent;
border-right: 32px solid transparent;
}

.triangle-left {
width: 0;
height: 0;
border-right: 32px solid #5394fd;
border-top: 32px solid transparent;
border-bottom: 32px solid transparent;
}

.triangle-right {
width: 0;
height: 0;
border-left: 32px solid #5394fd;
border-top: 32px solid transparent;
border-bottom: 32px solid transparent;
}
```

29 changes: 0 additions & 29 deletions content/snippets/css/s/triangle.md

This file was deleted.

0 comments on commit 5385769

Please sign in to comment.