Flipping a 2-dimensional box using CSS and incorporating cascading flex divs

*Please read the note:

This question is a bit lengthy as I wanted to explain my thought process. For those who prefer not to read everything, I have created codepens for easy reference.

Essentially, I am looking to achieve CSS box flipping effects like this: http://codepen.io/KDweber89/pen/MYRaxa

Initially, I started with this approach: http://codepen.io/KDweber89/pen/WbWQWV

...and ended up here, where I got the CSS flipping effect but lost my original styles. http://codepen.io/KDweber89/pen/QwPjeW

I'm struggling to make the flipping work while retaining the flex styling. Any ideas?

----------------------------------------------------------------------------

I have an app with cascading flex divs that look great. Now, I want to add 2-D box flipping to provide more information in each div.

Here's the original HTML and CSS code:

<div class="row">
  <div class="item">skittles</div>
  <div class="item">butter fingers</div>
  <div class="item">oreos</div>
  <div class="item">candy</div>
</div>

.row{
  margin: 5% auto;
  display: flex;
  display: -webkit-flex;
  flex-direction: row;
  -webkit-flex-direction: row;
}

.item {
  display: inline-block;
  margin: 10px auto;
  padding: 8px 15px;
  border-style: solid;
  border-color: black;  
}

The current setup looks good, and I want to build upon it: http://codepen.io/KDweber89/pen/MYRaxa

However, when I tried to add the flipping element, I faced some challenges.

My initial attempt was like this:

http://codepen.io/KDweber89/pen/WbWQWV

.row > .item{   
    position: absolute;
    transform: perspective( 600px ) rotateY( 0deg );
    background: white; width: 4em; height: 2em; border-radius: 7px;
    backface-visibility: hidden;
    transition: transform .5s linear 0s;
}

.row > .itemback{   
    position: absolute;
    transform: perspective( 600px ) rotateY( 180deg );
    background: white; width: 4em; height: 2em; border-radius: 7px;
    backface-visibility: hidden;
    transition: transform .5s linear 0s;
}

.row:hover > .item {
    transform: perspective( 600px ) rotateY( -180deg );
}

.row:hover > .itemback {
    transform: perspective( 600px ) rotateY( 0deg );
}


<div class="row">
  <div class="item">skittles</div>
  <div class="itemback">test</div>

  <div class="item">butter fingers</div>
  <div class="itemback">test</div>

  <div class="item">oreos</div>
  <div class="itemback">test</div>

  <div class="item">candy</div>
  <div class="itemback">test</div>
    </div>

However, this solution didn't quite work for me. While it gave me rotating effects, I lost the cascade flex style because I had to include a third div within my classes.

http://codepen.io/KDweber89/pen/QwPjeW

<div class = "row">
    <div class="threed">
        <div class="item"> skittles </div>
        <div class="itemback"> TEST </div>
    </div>

    <div class="threed">  
        <div class="item ">butter fingers</div>
        <div class="itemback"> TEST </div>
    </div>  
</div

In conclusion, can I achieve the desired flipping effect while maintaining the original cascading flex style? That's the challenge I'm facing.

Answer №1

The reason why the border is not showing up in your third codepen is due to a small error in the code:

.item, .itemback {
  display: inline-block;
  margin: 10px auto;
  padding: 8px 15px;
  border-style: solid;
  border-color: black;  
}

The ".item .itemback" selector indicates that the styles should be applied to .itemback elements inside .item elements. By adding a comma between them, the styles will be applied to both .item and .itemback elements like this: .item, .itemback.

I have made a few other tweaks that I believe bring you closer to achieving your goal. You can view the updated code here: http://codepen.io/ebelinski/pen/ByEGMG

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

Why does my jQuery IMG center script not work in Chrome and Safari, but it works perfectly in IE?

I am experiencing an issue with centering the thumbnails of products on my e-commerce website. Despite successful centering in IE, FF, and Opera, Chrome and Safari are not aligning the thumbnails properly – they remain at the top of the div instead of be ...

Is there an issue with my Regex pattern for extracting link elements when scraping content?

I'm currently facing an issue with my VB.NET scraper. The scraper is designed to extract all links from an HTML string that I have already retrieved, and upon inspection, the links are present. It appears that the problem lies within my regex expressi ...

Tips for transforming an SQL Server query into JSON format

I need to construct a table in a view utilizing the output of this particular SQL Query SELECT f.empresaid, e.fantasia AS Company, f.filialid, f.fantasia AS Branch, u.consultorid ...

Show or hide a div through two variables that toggle between different states

It's possible that I'm not fully awake, so missing the obvious is a possibility. However, I have 2 variables that determine whether a div has a specific class or not. The class functions more like a toggle; so the following conditions should tri ...

How can I convert an HTML table into a PDF using TCPDF while ensuring that all content is contained within a single div in PHP?

I have successfully converted my JSON API data into an HTML TABLE format and now I am trying to generate a PDF from this HTML TABLE using TCPDF in PHP. Despite trying various methods related to PDF generation using TCPDF, I am facing issues with my code wh ...

Showing a text value from a Github Gist on a Hugo website

I seem to be struggling with a seemingly simple task and I can't figure out what I'm missing. Any assistance would be greatly appreciated. I am working on generating a static site using Hugo. On one of my pages, I want to implement a progress ba ...

The issue I am facing is that when I click on a checkbox, only one of them seems to respond

When I click the button, only the first checkbox event is being checked while the rest of them are not. Can someone please provide some guidance on how to fix this issue? $("#cascadeChange").click(function() { //alert("Clicked"); ...

Only a select few expandable elements in the jQuery accordion

How can I create an accordion menu with only a few expandable options? I am looking to include the following items in my menu: Home, Support, Sales, Other The "Home" option is just a link without any sub-menu. Clicking on it should direct users to a spec ...

What is the best way to vertically align a pseudo element image using CSS?

After looking for similar questions, none of the answers seem to be working for my specific issue. This is what I'm struggling with: I am attempting to insert and center a decorative bracket image before and after certain content in the following man ...

The issue with jspdf is that it is failing to generate PDF documents of

I'm currently developing a resume builder app using ReactJS. One of the functionalities I'm working on is enabling users to download their resumes as PDFs. However, I've encountered an issue with the generated PDFs when using jsPDF. The down ...

Trouble encountered in aligning two DIVs in a horizontal position

I have been through numerous discussions on the same problem, but none of the solutions seem to work in my case. I am currently working on a section of my website that has 3 small boxes, each containing an image on top and text below. The issue arises when ...

The CSS slideshow is malfunctioning when displaying images retrieved from the database

I received a complimentary website layout to enhance my PHP skills. The website originally had slides on the index page, sourced directly from my computer when it was in index.html. However, now I have modified it to retrieve images from a database. Instea ...

Enhance Your List with Icon Decorations

Is it feasible to utilize a sprite image in place of the default bullet for an ul list? Is this achievable? ...

"Key challenges arise when attempting to execute the node app.js script through the terminal due to various middleware compatibility

I'm a beginner with node.js and I've encountered an issue while trying to run my node app.js file after incorporating a new file named projects.js which contains the following JS code: exports.viewProject = function(req, res){ res.render(" ...

Event Triggering in CakePHP

I am struggling with the onChange event in this code snippet. I must have overlooked something because it's not functioning as expected. Can someone please point out my mistake? Your assistance is greatly appreciated: <td class="cellInput"> & ...

State in Angular stubbornly refuses to switch despite condition changes

Here is the Typescript code, followed by the HTML: public verifySelection() { let choice = false; if (typeof this.formUser.permissionsTemplateID === undefined) { choice = true; } return choice; } <div class="form-group" ...

Tips for accessing an element using a specific identifier with the variable $key

PHP //This is the HTML code for quantity <p>Qty : <input type="number" value="" name="qty<?php echo $key ?> onChange="findTotal()"/> JS function function findTotal() { var arr = document.getElementsByName('qty'); // Calc ...

Trouble encountered while creating a table with the Bootstrap grid system

I'm attempting to create a table using the bootstrap grid system. The HTML code below is meant to generate the table, but I'm encountering an issue where the table cells overlap on screens with a width of 768px. .row.header { height: 44px; ...

Manipulating the location where a dropdown menu intersects with a button

Is there a way to adjust the drop-down menu positioning so that it aligns with the button on the top right side of the menu pop-up, rather than the top left as it currently does? Below is the code I have borrowed from an example on W3Schools. .dropbtn ...

Position the buttons in the react children's application

**Looking for help on positioning Black Widow in the center-left and Hulk at the bottom left of the screen. I'm having trouble figuring it out, does anyone have any tips? Also, I only want to isolate the buttons to each picture. Not sure if I need to ...