Add a foundation to this CSS pyramid

After experimenting with a demo I discovered at the following link: http://codepen.io/singhiskng/pen/dqiGj

My goal is to create a four-sided pyramid.

      <div id="pyramid-container">
        <div id="pyramid">
            <div class="face" id="front" ></div>
            <div class="face" id="back" ></div>
            <div class="face" id="left" ></div>
            <div class="face" id="right" ></div>
        </div>
     </div>

While I have successfully aligned the four sides, I am now hoping to add a base beneath them. I have tried to utilize a pseudo-element, create a square shape, and rotate it by 90 degrees. However, it does not seem to be appearing on the screen, and I am unsure of the reason:

#front::after{
    width:50px;
    height:50px;
    border-width:0;
    background-color:rgba(147,81,166,0.9);
    -webkit-transform:rotateX(90deg);
    -moz-transform:rotateX(90deg);
}

For reference, here is the link to my attempt: http://jsfiddle.net/r5Xjq/1/

It's worth noting that I have applied a 45-degree rotation to #pyramid in order to tilt the pyramid and view it from underneath.

Answer №1

To start, you must first create the :before (or :after) element and align its top edge with the bottom edge of a specific face (like the #front). This bottom face should have dimensions of 50x50. Once the alignment is complete, rotate the bottom face around the X-axis (along with the top edge) using the rotateX property. Since the #front face is already rotated by 30deg, the bottom face needs to be rotated by -120deg (-30deg to make it vertical, then another -90deg to align it properly at the base of the pyramid).

It's important to also ensure that the container's transform-style is set to preserve-3d, so the same value should be applied to the transform-style of the #front face. Here is the detailed CSS code:

#front{
    -webkit-transform-style:preserve-3d;
    -moz-transform-style:preserve-3d;

    -webkit-transform:rotateX(30deg);
    -moz-transform:rotateX(30deg); 
    border-bottom:50px solid rgba(147,81,166,0.9);               
}
#front:before {
    content:'';
    position:absolute;
    width:50px;
    height:50px;
    top:50px;
    left:-25px;               
    -webkit-transform-origin: 50% 0% 0;
    -moz-transform-origin: 50% 0% 0;
    -webkit-transform:rotate3d(1,0,0,-120deg);
    -moz-transform:rotate3d(1,0,0,-120deg);
    background: rgba(180,80,180,0.9);
    border:1px solid rgb(147,81,166,.5);
}

Check out the demo here.

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

Discover the steps to modify the input field type with just a keypress in angularjs

I need help changing an input field type from text to password. Currently, I am able to change the input field type from text to password when clicking on it. However, I also want the type to change from text to password when tab is pressed. Any assistan ...

Is it possible to use a shell script to replace the external CSS file link in an HTML file with the actual content of the CSS file

Seeking a solution for replacing external CSS and JS file links in an HTML document with the actual content of these files. The current structure of the HTML file is as follows: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C ...

I'm having trouble getting this button and icon to align properly. How can I fix this misalignment

Take a look at the HTML code snippet I'm currently working on... <div id="projects"> <H1 class="projects">PROJECTS</H1> <div class="box"></div> <div class="box"></div> <div class="box"></ ...

Customize the default classes for DataGrid in Material UI

Attempting to customize the CSS properties in the "DataGrid" Material UI, specifically adjusting font weight and overflow of the header. Below is the JSX code snippet: import React, {useState, useEffect} from 'react'; import {DataGrid, GridToolb ...

Ways to reduce the width of an input field: Utilizing Bootstrap v5 or employing CSS techniques

I am struggling to find a way to adjust the width of the input window. It seems like there is no specific code that controls the width of the input window. The code snippet below is extracted from the Bootstrap v5 documentation, specifically focusing on th ...

Troubling inconsistency in jQuery's .css function performance

I'm facing a problem with the jquery .css function. I am using it to retrieve the actual height of elements that have their height set to auto. The code I am currently using is as follows: $(this).css({ height: $(this).css("height"), width: $(this).c ...

Hexagonal border with embedded image

I'm striving to achieve the image below: https://i.sstatic.net/iZIex.png I've managed to create a hexagon border and text, but I'm unsure how to incorporate the hexagon image and create a grid of 3 hexagons. Any assistance would be greatl ...

Consistently maintaining a uniform distance between icons and the border box is essential

I am working on a team overview for a company where data such as name, job title, and information are fetched from the database. Due to varying lengths of information, the icons are not aligning properly in one line. https://i.sstatic.net/cEmKj.png Does ...

Tips for maintaining the nested collapsible table row within the main table row in a React MUI table

I am working on implementing a Material UI (MUI) table that includes collapsible table rows. The challenge I am facing is maintaining consistent border and background colors across all the rows, even when some are collapsed. Currently, the separate rows ar ...

Is there a way to show textboxes stacked on top of each other without causing them to

Here is the HTML snippet I am working with: <div> <p><label>Faculty <input type="text" class = "f"></label></p> <p><label >Department<input type="text" class = "f"></label></p> ...

Visual Delights on the Menu

I am having trouble adding a "Home" picture to my menu. It keeps showing up as a blank square, even though I have tried using both .png and .jpg formats. Here is the code that I am currently using: <div id='cssmenu'> <link rel= ...

Determine the width of a div by utilizing SASS and following a series of incremental steps

Let's discuss the current scenario: I have a parent div that consists of multiple child elements which vary in number. (2, 3, 4) The goal is to determine the appropriate width for each step element dynamically: For 2 steps: 50% For 3 steps: 33.3% ...

How to horizontally center a div between two floated elements

Check out this JSFiddle example. I'm facing a challenge in horizontally centering the div class="filter-group" between two floated buttons within the given example. I've tried various methods but haven't been successful so far. Any assistan ...

Tips for modifying the color of selected text

Is there a way to change the color of the dropdown text? Currently, it is set to red but initially appears as black. When clicked on, it changes to red. How can I make it so that the color is initially displayed as red? <select> <option style ...

A combination of fixed width column and dynamic content area in Bootstrap design

Is there a way to achieve the combination of fixed and fluid width columns using Twitter Bootstrap alone, similar to this example? The HTML and CSS in the example make it seem simple. But can this be done solely with Bootstrap? ...

The erratic appearance of inactive elements within ExtJS components

I am currently working on an ExtJS form that utilizes hbox-layout containers to generate sentences containing various form inputs. There is a specific requirement to disable the form under certain conditions. These hbox-layout containers consist of compone ...

Opacity: When the value is set to 0, the element remains invisible even when hovered over

I'm encountering an issue with configuring an element to have absolute positioning and a width and height of 100% while setting its opacity to 1.0. To summarize, here is the HTML code I am working with: <ul class="properties"> <li style ...

What is the best way to design bootstrap-style menus in React using TailwindCSS or styled-components?

As I dive into learning React, I find myself torn between using TailwindCSS and styled-components. While I am attracted to the simplicity of styled-components, I am hesitant about the lack of pre-built features that TailwindCSS offers, especially in terms ...

The alignment of the Div element is incorrect following a fixed video in bootstrap

When I place a div after the video, the div appears on top of the video instead of after it. Additionally, when I change min-width: 100% to width: 100%, the content appears before the video when I resize the browser. body{ font-family: 'Mina', ...

Transitioning between pages causes a delay in loading the background

Today as I was working on my CSS, I encountered some issues. I utilized Bootstrap and Darkstrap for designing. In Darkstrap, the style for the body is body { color: #c6c6c6; background-color: #2f2f2f; } Meanwhile, in my own CSS: body { ...