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

Press on a rectangle inside an HTML5 SVG program

I'm currently developing a web application that utilizes the svg and Raphael library: workflowEditor.show(); var myList = document.getElementsByTagName("rect"); for (var a = 0; a < myList.length; a++) { myList[a].addEventListener("OnClick", f ...

What is causing my anchor tags not to reflow properly?

I've been working on my new website and I'm facing a challenge that I just can't seem to solve. Here's the link: When I resize my browser to "mobile width", making it narrower than the row of oval "Tags" below my site menu, I want the ...

Something strange happening with the HTML received after making a jQuery AJAX request

My PHP form handler script echoes out some HTML, which is called by my AJAX call. Below is the jQuery code for this AJAX call: $(function() { $('#file').bind("change", function() { var formData = new FormData(); //loop to add ...

Weather Application featuring Circular Slider

I've been on the hunt for a circular slider animation. Imagine it working like this: <input type="range" min="0" max="50" value="0" step="5" onchange="showValue(this.value)" /> <span id="range">0</span> function showValue(newValue ...

Exploring the concept of nested views in AngularJS's UI Router with multiple views integration

I am facing an issue with configuring multiple views on one page, where one view is nested within another. My code in app.js does not seem to be working properly. Below are the details: This is my index.html file <body ng-app="configuratorApp" > ...

How to conditionally set the active class in a React component

I am new to using React and I am encountering some issues. My goal is to add an active class when any of these components are opened. I have attempted a solution but it isn't working as expected. I need assistance in adding a background color to the d ...

What is the best way to retrieve the src value upon clicking on an image in a JavaScript function with multiple images displayed on

I have 3 images on my website. Each time I click on an image, I want to retrieve the source value. I attempted the code below, but it doesn't seem to work with multiple images. <div class="test"> <a href="#" class="part-one" ...

What strategies can I use to divide lengthy words in my Django application?

My username on the site is causing overflow outside of the content box, as shown here I tried adding h1, h2, h3, h4, h5, h6 { color: #44444; overflow-wrap: break-word;}, but it didn't work. Here is the code for the profile page: All CSS styles for ...

What is the best way to center this menu on the web page?

Is there a way to center this menu on the web page for better alignment? Any suggestions on improving the code are welcome. Thank you in advance. Edit: Also, how can I modify the hover effect to change the background color to green and make it expand full ...

Cross-browser compatibility issues preventing CSS button effects from functioning properly

Experiencing some challenges with CSS Button effects not functioning consistently across different browsers. The display is satisfactory in Chrome, but not in Firefox. Struggling to pinpoint the source of the issue. Here is my current setup: Fiddle a ...

HighCharts fails to display on Polymer webpage

I am working on a project that involves using Polymer alongside HighCharts. Here is the code I have implemented: HTML : <div class="container" layout vertical center> <paper-shadow z="1" class="span-shadow"> <post-card id ...

The forecast button seems to be malfunctioning. Each time I attempt to click on it, a message pops up saying, "The server failed to comprehend the request sent by the browser (or proxy)."

Even though I provided all the necessary code, including the Flask app, predictionmodel.py, and HTML code, I am still encountering an error when running it locally after clicking submit. The browser (or proxy) sent a request that this server could not un ...

Building a dynamic tab menu using JavaScript: A step-by-step guide

In order to generate dynamic tab menus with JavaScript, I am seeking a solution that does not rely on jQuery as it may not be supported by all mobile devices. Any advice for replicating the same functionality using pure JavaScript would be greatly apprec ...

Deleting a property once the page has finished loading

My issue is a bit tricky to describe, but essentially I have noticed a CSS attribute being added to my div tag that seems to come from a node module. The problem is, I can't seem to find where this attribute is coming from in my files. This attribute ...

The navbar in mobile view is not affected by the z-index property

Having created a navbar with scroll effect, I am encountering an issue with the mobile responsive view. Can someone please assist me in solving this problem? I would like to position the bottom nav-list below the navbar in the mobile view when clicking on ...

Looking for a way to exclude both parents and children from a list of relatives? Want to ensure that the

I've been struggling to align these list elements with their counterparts, but they seem to automatically create a margin for their child elements. It is essential for these list items to maintain the position:relative attribute so that the #dropdown ...

The ng-route feature seems to be malfunctioning and I am unable to identify the error, as no information is being displayed in the console

Here is the code in my boot.php file where I have set up the links <ul class="nav nav-pills nav-stacked"> <li role="presentation"><a href="#/valley">Valley</a></li> <li role="presentation"><a href="#/beach"> ...

How can I prevent a browser from allowing users to select an image tag?

I'm dealing with an issue on my webpage where I have an image that is inadvertently picking up mouse clicks, causing the browser to perform drag and drop actions or highlight the image when clicked. I really need to use the mousedown event for somethi ...

The height of the href is not displaying correctly when the text-decoration is disabled and it is placed next to

In my design, I have a link positioned next to an image with perfect vertical alignment. Everything looks great when the text has the standard text-decoration, centered vertically and all that. However, as soon as I remove the text-decoration, leaving the ...

Guide to configuring an Angular Material Footer using Flex-Layout

Could someone help me with setting up the footer in my Angular Material app? I want it to: stick to the bottom when the content height is smaller than the view-port move down or get pushed down when the content height exceeds the view-port One important ...