DEV Community

Cover image for CSS 3D shapes
Jayesh Tembhekar โšก
Jayesh Tembhekar โšก

Posted on โ€ข Edited on

32 5

CSS 3D shapes

Welcome to the CSS 3D shapes folks ๐Ÿฅ

Yes, you can

But, How ?

Lets see our Two examples down below

Lets make a three dimensional shapes just by some CSS3 properties.


3D Cube ๐Ÿฅค

Some basic HTML markup below :



<body>

    <div class="container">
        <div class="cube"></div>
    </div>

</body>


Enter fullscreen mode Exit fullscreen mode

Now the real magic ๐ŸŽƒ happens with this CSS3 code below :



  .container
    {
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50% , -50%);
    }

   .cube
    {
        background: #dc2e2e;
        width: 100px;
        height: 100px;
        position: relative;
        margin: 50px;
    }

   .cube::before
    {
        content: '';
        display: inline-block;
        background: #f15757;
        width: 100px;
        height: 20px;
        transform: skewX(-40deg);
        position: absolute;
        top: -20px;
        left: 8px;
    }

   .cube::after
    {
        content: '';
        display: inline-block;
        background: #9e1515;
        width: 16px;
        height: 100px;
        transform: skewY(-50deg);
        position: absolute;
        top: -10px;
        left: 100%;
    }


Enter fullscreen mode Exit fullscreen mode

Uffff ๐Ÿ˜“

Thats a lot of code...

Atlast, you will see a cube like this ๐Ÿ‘‡

3D cube


3D Pyramid ๐Ÿ”ฑ

Some basic HTML markup below :



<body>

    <div class="container">
        <div class="pyramid"></div>
    </div>

</body>


Enter fullscreen mode Exit fullscreen mode

Now, magical CSS3 in action :



  .container
    {
        position: absolute;
        left: 50%;
        top: 35%;
        transform: translate(-50px , -35px);
    }

  .pyramid
    {
        width: 100px;
        height: 200px;
        position: relative;
        margin: 50px;
    }

  .pyramid::before, .pyramid::after
    {
        content: '';
        display: inline-block;
        width: 0;
        height: 0;
        border: 50px solid;
        position: absolute;
    }

  .pyramid::before
    {
        border-color: transparent transparent #7700ff transparent;
        transform: scaleY(2) skewY(-40deg) rotate(45deg);
    }

  .pyramid::after
    {
        border-color: transparent transparent #5500b6 transparent;
        transform: scaleY(2) skewY(40deg) rotate(-45deg);
    }


Enter fullscreen mode Exit fullscreen mode

Pyramid will look like this ๐Ÿ‘‡

3D Pyramid




๐Ÿฅ‚๐Ÿฅณ

We did it, 3D shapes are looking ๐Ÿ”ฅ

Thank you Devs for hanging out.
Now, go & roll out your editors & make some โ„ shapes.
Till then see you in the next post ๐Ÿ“ฎ

Also do check my previous posts

Author:
Instagram โžก Jayesh.2112 ๐Ÿ’
Twitter โžก Developer_Codes ๐Ÿ’™

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more