3D Folding Menu Effect With CSS

I have been playing around with the 3D capability CSS3 offers and really had fun with it. But having fun on your own is not really fun right? So I decided to share this with you by creating a menu with a nice 3D effect on rollover without using any JavaScript. To achieve this effect I am going to use the perspective CSS property so let’s have some fun together.

HTML

Let’s get started with the HTML.

<div id="menu">
    <div id="end-rib-left">
        <div id="rib-left"></div>
    </div>
    <div id="all-bts">
        <div id="pos-bt1">
            <a href="#" class="bt-wrapper">HOME</a>
        </div> 
        <div id="pos-bt2">
            <a href="#" class="bt-wrapper">ABOUT</a>
        </div> 
        <div id="pos-bt3">
            <a href="#" class="bt-wrapper">CONTACT</a>
        </div> 
    </div>
</div>

CSS

I am giving you the CSS for the ribbon effect but if you are not interested you can go to the next snippet.

#end-rib-left {
    width: 0px;
    height: 50px;
    margin: 30px auto 40px;
    padding: 20px 10px;
    position: relative;
    background: #87C695;
    float: left;
}

#end-rib-left:before {
    position: absolute;
    left: -78px;
    bottom: -18px;
    border: solid 45px #6A9666;
    border-right-width: 50px;
    border-left-color: transparent;
    content: "";
    z-index: -1;
}

#end-rib-left #rib-left:before {
    position: absolute;
    bottom: -18px;
    border-style: solid;
    border-color: #557F4F transparent;
    content: "";
    left: 0;
    border-width: 18px 0 0 18px;
}
Here is where the magic happens.
#menu {
    width: 380px;
    margin: 0 auto;
}

.bt-wrapper {
    width: 120px;
    height: 90px;
    margin-top: 30px;
    line-height: 90px;
    text-align: center;
    text-decoration: none;
    color: #fff;
    background:#7EB78B;
    float:left;
    display: block;
    z-index: 100;
            transform-origin: left center;
        -ms-transform-origin: left center;
    -webkit-transform-origin: left center;
            transition: all 300ms ease-in-out;
    -webkit-transition: all 300ms ease-in-out;
}

#all-bts {
    position: relative;
}

#pos-bt1, #pos-bt2, #pos-bt3 {
    height: 150px;
    position: absolute;
    transform-style: preserve-3d;
            perspective: 500px;
       -moz-perspective: 500px;
    -webkit-perspective: 500px;
}

#pos-bt2 {
    left: 120px;
}

#pos-bt3 {
    left: 240px;
}

.bt-wrapper:hover {
            transform: translate3d(0,0,0) rotate3d(0,1,0,-30deg);
        -ms-transform: translate3d(0,0,0) rotate3d(0,1,0,-30deg);
    -webkit-transform: translate3d(0,0,0) rotate3d(0,1,0,-30deg);
}

.bt-wrapper:hover .bt{
    background: #77A874;
}

The most important things to remember in order to make this work are first to create a wrapper div and apply the perspective CSS property to it. In this tutorial the wrappers are #pos-bt1, #pos-bt2, #pos-bt3. Then inside your wrapper you need to add the element to which the effect will be applied (in our case it’s the a element) and you apply the transform property to it.

And just to finish off the ribbon you can add the following.
#pos-bt3:after {
    top: 30px;
    position: absolute;
    border: solid 45px #7EB78B;
    border-left-width: 10px;
    border-right-color: transparent;
    content: "";
    z-index:-2;
}

I hope you enjoyed this tutorial. Don’t forget to leave a comment and share.

6 thoughts on “3D Folding Menu Effect With CSS

    1. @hifzur the perspective property is a CSS3 feature so no way it works on old IE browsers unless someone finds a way to re-create this effect using JavaScript.

  1. Neat concept.
    Interestingly it's not quite working on my WinXP system running latest Chrome Version 27.0.1453.110 m. My onboard graphics are from 2006, so maybe that's the key. The 'shrinking' to the left works, but the top and bottom don't skew out, they stay horizontal.

    1. @Jim N I just tried on a very old computer with the same version of Chrome than you and it works just fine.
      After some research I found that in order to make this effect work on Chrome (and maybe any browsers) you need to have GPU acceleration enabled. You can check that by typing about:GPU in the address bar and see what it says. If this is the problem read this: https://www.laptopmag.com/articles/enabl… and see if it can help.

Leave a Reply

Your email address will not be published. Required fields are marked *