mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-08-11 16:44:57 +02:00
122 lines
2.2 KiB
Plaintext
122 lines
2.2 KiB
Plaintext
---
|
|
category: Display
|
|
created: '2021-04-04'
|
|
description: Create a 3D card with CSS
|
|
keywords: css 3D card
|
|
thumbnail: /assets/css-layout/thumbnails/three-dimensions-card.png
|
|
title: Three dimensions card
|
|
---
|
|
|
|
## HTML
|
|
|
|
```html index.html
|
|
<div class="three-dimensions-card">...</div>
|
|
```
|
|
|
|
## CSS
|
|
|
|
```css styles.css
|
|
:root {
|
|
--three-dimensions-card-left-side-width: 1rem;
|
|
}
|
|
|
|
.three-dimensions-card {
|
|
position: relative;
|
|
}
|
|
|
|
/* The left side */
|
|
.three-dimensions-card::before {
|
|
background: #d1d5db;
|
|
content: '';
|
|
|
|
/* Position */
|
|
top: var(--three-dimensions-card-left-side-width);
|
|
left: 0px;
|
|
position: absolute;
|
|
transform: translate(-100%, 0) skewY(-45deg);
|
|
transform-origin: left top;
|
|
|
|
/* Size */
|
|
height: 100%;
|
|
width: var(--three-dimensions-card-left-side-width);
|
|
}
|
|
|
|
/* The bottom side */
|
|
.three-dimensions-card::after {
|
|
background: #d1d5db;
|
|
content: '';
|
|
|
|
/* Position */
|
|
bottom: 0px;
|
|
left: 0px;
|
|
position: absolute;
|
|
transform: translate(0, 100%) skewX(-45deg);
|
|
transform-origin: left top;
|
|
|
|
/* Size */
|
|
height: var(--three-dimensions-card-left-side-width);
|
|
width: 100%;
|
|
}
|
|
```
|
|
|
|
<Playground>
|
|
```css styles.css hidden
|
|
:root {
|
|
--three-dimensions-card-left-side-width: 1rem;
|
|
}
|
|
|
|
body {
|
|
align-items: center;
|
|
display: flex;
|
|
justify-content: center;
|
|
}
|
|
|
|
.three-dimensions-card {
|
|
position: relative;
|
|
|
|
/* Demo */
|
|
border: 1px solid #d1d5db;
|
|
height: 6rem;
|
|
width: 6rem;
|
|
}
|
|
|
|
/* The left side */
|
|
.three-dimensions-card::before {
|
|
background: #d1d5db;
|
|
content: '';
|
|
|
|
/* Position */
|
|
top: var(--three-dimensions-card-left-side-width);
|
|
left: 0px;
|
|
position: absolute;
|
|
transform: translate(-100%, 0) skewY(-45deg);
|
|
transform-origin: left top;
|
|
|
|
/* Size */
|
|
height: 100%;
|
|
width: var(--three-dimensions-card-left-side-width);
|
|
}
|
|
|
|
/* The bottom side */
|
|
.three-dimensions-card::after {
|
|
background: #d1d5db;
|
|
content: '';
|
|
|
|
/* Position */
|
|
bottom: 0px;
|
|
left: 0px;
|
|
position: absolute;
|
|
transform: translate(0, 100%) skewX(-45deg);
|
|
transform-origin: left top;
|
|
|
|
/* Size */
|
|
height: var(--three-dimensions-card-left-side-width);
|
|
width: 100%;
|
|
}
|
|
```
|
|
|
|
```html index.html hidden
|
|
<div class="three-dimensions-card"></div>
|
|
```
|
|
</Playground>
|