Pyramid structure with multiple layers in 3D dimensions

Is it possible to create a 3D multi-level pyramid using CSS and HTML5? I have explored some shape generator websites, but they are not compatible with IE and FF.

For example:

I also attempted to create a 2D multi-level pyramid, but it did not meet my requirements.

.container1>div:hover {
  border-bottom: 25px lightblue solid !important;
}
#trapezoid11 {
  border-bottom: 25px solid blue;
  border-left: 25px solid transparent;
  border-right: 25px solid transparent;
  height: 0;
  width: 0px;
  margin: 0 auto;
}
#trapezoid12 {
  border-bottom: 25px solid green;
  border-left: 25px solid transparent;
  border-right: 25px solid transparent;
  height: 0;
  width: 50px;
  margin: 0 auto;
}
#trapezoid13 {
  border-bottom: 25px solid red;
  border-left: 25px solid transparent;
  border-right: 25px solid transparent;
  height: 0;
  width: 100px;
  margin: 0 auto;
}
#trapezoid14 {
  border-bottom: 25px solid blue;
  border-left: 25px solid transparent;
  border-right: 25px solid transparent;
  height: 0;
  width: 150px;
  margin: 0 auto;
}
#trapezoid15 {
  border-bottom: 25px solid red;
  border-left: 25px solid transparent;
  border-right: 25px solid transparent;
  height: 0;
  width: 200px;
  margin: 0 auto;
}
.container1 {
  width: 90%;
  margin: 0 auto;
}
<div class="container1 ">
  <div id="trapezoid11"></div>
  <div id="trapezoid12"></div>
  <div id="trapezoid13"></div>
  <div id="trapezoid14"></div>
  <div id="trapezoid15"></div>

</div>

The desired final result can be viewed here: https://i.sstatic.net/fGjDz.png

Answer №1

To create a stunning pyramid design, you can use just one HTML element along with some pseudo-elements that have gradient backgrounds:

div{
    height:150px;
    position:relative;
    transform:translate(-50%,-50%) rotate(-7deg);
    transform-origin:50% 0;
    width:200px;
    left:50%;
    top:50%;
}
div::before,div::after{
    background-origin:border-box;
    border-top:150px solid #fff;
    bottom:0;
    content:"";
    position:absolute;
    top:0;
}
div::before{
    background-image:linear-gradient(14deg,transparent 25px,#d00 25px,#d00 calc(25% + 25px),#a50 calc(25% + 25px),#a50 calc(50% + 12px),#fc0 calc(50% + 12px),#fc0 75%,#ff0 75%);
    background-position:2px 0;
    background-repeat:no-repeat;
    border-right:100px solid transparent;
    left:0;
    right:50%;
}
div::after{
    background-image:linear-gradient(-14deg,transparent 25px,#a00 25px,#a00 calc(25% + 25px),#840 calc(25% + 25px),#840 calc(50% + 12px),#da0 calc(50% + 12px),#da0 75%,#dc0 75%);
    background-position:-2px 0;
    background-repeat:no-repeat;
    border-left:100px solid transparent;
    left:50%;
    right:0;
}
html,body{background:#fff;height:100%;}
<div></div>

If you want a "usable" pyramid where you can insert content, there are a few methods available. You'll need to adjust the padding in each child div to center the content and wrap the content within tags to avoid skewing.

*{box-sizing:border-box;margin:0;padding:0;}
html,body{background:#fff;height:100%;}
#pyramid{
    height:425px;
    left:50%;
    overflow:hidden;
    padding:0 0 25px;
    position:relative;
    top:50%;
    transform:translate(-50%,-50%) skewy(-5deg);
    width:500px;
}
#pyramid::before,#pyramid::after{
    background-origin:border-box;
    border-top:400px solid #fff;
    bottom:0;
    content:"";
    pointer-events:none;
    position:absolute;
    top:0;
}
#pyramid::before{
    border-right:250px solid transparent;
    left:0;
    z-index:5;
}
#pyramid::after{
    border-left:250px solid transparent;
    right:0;
    z-index:5;
}
#pyramid>div{
    height:25%;
    position:relative;
}
#pyramid>div::before,#pyramid>div::after{
    border-top:26px solid;
    bottom:-25px;
    content:"";
    pointer-events:none;
    position:absolute;
}
#pyramid>div::before{
    border-left:250px solid transparent;
    left:0;
}
#pyramid>div::after{
    border-right:250px solid transparent;
    right:0;
}
#level1{
    background:linear-gradient(90deg,#ff0 50%,#dc0 50%);
    z-index:4;
}
#level1::before{
    color:#ff0;
}
#level1::after{
    color:#dc0;
}
#level2{
    background:linear-gradient(90deg,#fc0 50%,#da0 50%);
    z-index:3;
}
#level2::before{
    color:#fc0;
}
#level2::after{
    color:#da0;
}
#level3{
    background:linear-gradient(90deg,#a50 50%,#840 50%);
    z-index:2;
}
#level3::before{
    color:#a50;
}
#level3::after{
    color:#840;
}
#level4{
    background:linear-gradient(90deg,#d00 50%,#a00 50%);
    z-index:1;
}
#level4::before{
    color:#d00;
}
#level4::after{
    color:#a00;
}
#pyramid>div>*{
    transform:skewy(5deg);
}
<section id="pyramid">
    <div id="level1"></div>
    <div id="level2"></div>
    <div id="level3"></div>
    <div id="level4"></div>
</section>

*{box-sizing:border-box;margin:0;padding:0;}
html,body{background:#fff;height:100%;}
#pyramid{
    height:425px;
    left:50%;
    overflow:hidden;
    padding:0 0 25px;
    position:relative;
    top:50%;
    transform:translate(-50%,-50%) skewy(-5deg);
    width:500px;
}
#pyramid::before,#pyramid::after{
    background-origin:border-box;
    border-top:400px solid #fff;
    bottom:0;
    content:"";
    pointer-events:none;
    position:absolute;
    top:0;
}
#pyramid::before{
    border-right:250px solid transparent;
    left:0;
    z-index:5;
}
#pyramid::after{
    border-left:250px solid transparent;
    right:0;
    z-index:5;
}
#pyramid>div{
    height:25%;
    position:relative;
}
#pyramid>div::before,#pyramid>div::after{
    content:"";
    pointer-events:none;
    position:absolute;
}
#pyramid>div::before{
    border-left:250px solid transparent;
    border-right:250px solid transparent;
    border-top:26px solid;
    bottom:-25px;
    left:0;
    z-index:1;
}
#pyramid>div::after{
    border-top:125px solid rgba(0,0,0,.25);
    border-right:1200px solid transparent;
    left:50%;
    top:0;
    z-index:2;
}
#level1{
    background:#ff0;
    z-index:4;
}
#level1::before{
    color:#ff0;
}
#level2{
    background:#fc0;
    z-index:3;
}
#level2::before{
    color:#fc0;
}
#level3{
    background:#a50;
    z-index:2;
}
#level3::before{
    color:#a50;
}
#level4{
    background:#d00;
    z-index:1;
}
#level4::before{
    color:#d00;
}
#pyramid>div>*{
    transform:skewy(5deg);
    position:relative;
    z-index:3;
}
<section id="pyramid">
    <div id="level1"></div>
    <div id="level2"></div>
    <div id="level3"></div>
    <div id="level4"></div>
</section>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

png showing the backdrop, not the background image

Struggling with aligning multiple layers on my website. The primary background of my site is a sleek black #000000. Next, there's a div featuring a centered background image that complements the black backdrop perfectly. I'm attempting to over ...

socket.io and the use of various chat rooms

Is it possible for a client socket in a browser to connect to multiple rooms (3-5) and receive separate messages from each room while using node.js to send messages to all clients in the same room? ...

Updating style of element in EJS following POST request in Node.js using Express

I am working on a form page that is supposed to display a Success Alert (Boostrap) once the user fills out the form and clicks the Submit button. <form class="well form-horizontal" action="/contact" method="post" id="contact_form"> ... (input fiel ...

arrange and position elements using bootstrap's grid system

I'm currently utilizing bootstrap for my web application and aiming to have my divs display in a specific layout: https://i.sstatic.net/pJHmn.png Below is the snippet of my HTML code: <div class="row"> <div class="col-lg-8 col-md-12 co ...

Storing a webpage in HTML with the use of @import function in CSS

I'm looking to save an entire HTML page, but I'm running into an issue with the CSS file that includes the line: import url('someOtherCss.css'); When attempting to save the page using Firefox or Chrome with 'File->Save Page a ...

Having problems with jQuery's document.on hover toggle method?

Recently, I've been trying to implement a jQuery function that toggles an image when hovering over an element and toggles it back when exiting the element. However, I encountered a problem when using the $(document).on selector. I attempted to use $(d ...

What is the reason for the website allowing me to scroll towards the right?

I'm encountering a strange issue with my code that I can't seem to figure out. The website keeps letting me scroll to the right as if there's an image or something off-screen, even though there isn't anything there. Any idea why this is ...

"Utilizing a media query to display an anchor link at the top based

How can I create a "Back to Top" link that automatically scrolls mobile and tablets to the top of the page? Usually, I would achieve this using JavaScript by detecting the window and body height. Is it possible to accomplish this using a media query? @me ...

Unable to locate the JavaScript/jQuery key

Struggling with a dictionary in JavaScript being passed to a function in Django. Despite the key existing, I'm getting an error saying 'key message not found'. As a newbie in Javascript and JQuery, I must have made a simple mistake somewhere ...

Ways to correct a jQuery error

Recently stumbled upon this code snippet on codeply and decided to try it out in Visual Studio. Oddly enough, everything appeared fine on the snippets page, but when I ran it on my own computer, I encountered this https://i.sstatic.net/wmGII.png. It's ...

Dynamic content is not present on the Nivo Slider

I'm having trouble figuring out why the one image is not changing. I've checked for jQuery errors but couldn't find any. Just to clarify, the styling is correct as the client requested it to be a link in case you think there is an issue. T ...

Extracting information from the 'View all responses' feature

I've been attempting to extract reviews from the following website: . Each review contains 5 ratings such as value for money and customer service. However, most of the information is initially hidden behind a 'See all Answers' button, restri ...

Guide to altering the color of the row that is clicked in a table using css and jquery

Is there a way to change the text color of a row in a table when it is clicked, similar to an example like this but without changing the background color? The code I have tried is not working for me. Below is a snippet of the code I am using: $("#myTab ...

Generate individual CSS files using postcss and rollup

When I import each css file in my JavaScript, I want it to generate a new css file for the build. For example: import "./app.css"; import "./admin.css"; This would result in creating dist/app.css and dist/admin.css. My configuration fi ...

Avoiding a line break between two <form> tags is essential for maintaining the structure of your webpage

I am looking for a way to ensure that there are no line breaks between two forms that I have on my website. Here is the code snippet: <form action="..."> <input type="submit" /> </form> LINE BREAK HERE <form action="..."> <inpu ...

PubNub's integration of WebRTC technology allows for seamless video streaming capabilities

I've been exploring the WebRTC sdk by PubNub and so far, everything has been smooth sailing. However, I'm facing a challenge when it comes to displaying video from a client on my screen. Following their documentation and tutorials, I have writte ...

Using jQuery to toggle the visibility of divs depending on the selection of multiple checkboxes

I found this code snippet that I need help with. <div class="row"> <div class="col-xs-4"> <label class="checkbox-inline"><input type="checkbox" value="draft">Draft</label> </div> <div class="c ...

Increase the size of images on the same screen with a click using WP Metas

Currently, I am utilizing WP Metaslider for a slideshow/gallery presentation. While it is functioning well, I would like to enhance the user experience by allowing the images in the slider to enlarge within the slide when clicked on, rather than opening in ...

The scraping code built on Selenium encounters an issue with the NoSuchElementException error

I wrote a Python script that extracts various data. One of the tasks is to extract the Website from this HTML code: <a data-ix="show-popup-on-click" target="_blank" rel="nofollow" href="https://mylink.org/" class="button full w-button" style="transitio ...

Putting a Pause on CSS Transition using jQuery

I am attempting to delay a CSS transition for an element by using a delay function, with an additional 0.2s applied to make it slide 0.2s later than the initial delay of the main wrapper. I am applying a class to give it a transition effect to slide from r ...