Ways to conceal a text-filled div behind an image using 3D transformation

I've been working on creating three images with a fun 'flipcard' effect for the past day and a half, and I believe I'm getting closer to achieving my goal.

However, there is one issue remaining, as you can see in the codepen. When the images are in their static state (not being hovered over), the text on top of them is still visible.

If anyone has any ideas on how to hide the text when the images are static, but have it appear when they are hovered over and animate with the 'flipcard' effect, I would greatly appreciate it!

Essentially, I want the text to be hidden or removed when the images are static, but then become visible after the flip animation - almost as if it's on the backside of the images! Everything else seems to be working fine.

Thank you in advance for any solutions, much appreciated! :-)

Codepen link - http://codepen.io/skoster7/pen/kkYEJk?editors=0100

HTML:

<div class="flexcontainer">
    <div class="photo-container">
        <div class="photo">
            <img src="https://media2.giphy.com/media/kiXLfqncf42kg/200_s.gif" class="front" />
            <div class="photo-desc back">Christmas tree</div>
        </div>
    </div>

    <div class="photo-container">
        <div class="photo">
            <img src="http://hdwallpaperpoint.com/wp-content/uploads/2016/05/Happy-birthday-candles-on-cake-small-cake-hd-4k-wallpaper-300x200.jpg" class="front" />
            <div class="photo-desc back">Happy Birthday</div>
        </div>
    </div>

    <div class="photo-container">
        <div class="photo">
            <img src="https://www.walldevil.com/wallpapers/a76/thumb/halloween-jack-o039-lantern-pumpkin-ghost-cat-skull-spider.jpg" class="front" />
            <div class="photo-desc back">Halloween</div>
        </div>
    </div>
</div>

CSS:

.flexcontainer {
    display: flex;
    perspective: 700px;
}

.photo {
    position: relative;
    z-index: 1000;
}

.photo-desc {
    position: relative;
    z-index: 100;
}

.photo-container {
    position: relative;
    margin-right: 10px;
    transition-property: transform;
    transition-duration: 2s;
    transition-style: preserve-3d;
    backface-visibility: hidden;
}

    .photo-container:hover {
        transform: rotateY(-180deg);
    }

.back {
    backface-visibility: visible;
    position: absolute;
    top: 10;
    margin-top: -200px;
    transform: rotateY(-180deg);
    color: red;
}

Answer №1

The photo and back elements should be positioned as siblings rather than parent/child.

Here is a code snippet with adjusted dimensions:

.flexcontainer {
  display: flex; 
  perspective: 700px; 
}

.photo {
  width: 200px;
  height: 150px; 
  transform: rotateY(0deg); 
}
.photo img {
  width: 200px;
  height: 150px;
}

.photo-container {
  transform-style: preserve-3d;
  transition-property: transform;
  transition-duration: 2s; 
  position:relative;
  width: 200px;
  height: 150px; 
  margin:10px;
}

.photo-container:hover {
  transform: rotateY(-180deg); 
}

.back {
  transform: rotateY(180deg); 
  color: red;
}
.photo,
.back {
  backface-visibility: hidden; 
  position:absolute;
  left:0;
  top:0;
}
.back {
  transform: rotateY(180deg); 
}
<div class="flexcontainer">

  <div class="photo-container">
    <div class="photo">
      <img src="https://media2.giphy.com/media/kiXLfqncf42kg/200_s.gif" class="front">
    </div>
    <div class="back">Christmas tree</div>
  </div>

  <div class="photo-container">
    <div class="photo">
      <img src="http://hdwallpaperpoint.com/wp-content/uploads/2016/05/Happy-birthday-candles-on-cake-small-cake-hd-4k-wallpaper-300x200.jpg" class="front">
    </div>
    <div class="back">Happy Birthday</div>
  </div>

  <div class="photo-container">
    <div class="photo">
      <img src="https://www.walldevil.com/wallpapers/a76/thumb/halloween-jack-o039-lantern-pumpkin-ghost-cat-skull-spider.jpg" class="front">
    </div>
    <div class="back">Halloween</div>
  </div>
</div>

You can view a live example on CodePen:
http://codepen.io/anon/pen/Egazvq?editors=1100

Answer №2

To achieve the desired effect, simply include display: none; in the styling for the .back class.

Additionally, add the following CSS code:

.photo-container:hover .back {
  display: block;
}

Check out this updated example on CodePen:

http://codepen.io/user123/pen/XyZabc?editors=1001

Answer №3

I really enjoyed tackling this challenge and have come up with another solution for you.

.flexcontainer {
  display: flex; 
  perspective: 700px; 
}

.photo-desc { 
  position: absolute; 
}

.photo-container {  
  position: relative; 
  z-index: 100;  
  margin-right: 10px; 
  transition-property: transform;
  transition-duration: 2s; 
  transition-style: preserve-3d; 
}

.photo-container:hover {
  transform: rotateY(-180deg);
  backface-visibility: visible;
}

.back {
  position: absolute;
  top: 10; 
  margin-top: -200px; 
  transform: rotateY(180deg);
  color: red; 
  opacity: 0;
}
.photo-container:hover > .back {
  opacity: 1;
  transition: opacity 1s linear;
}
<div class="flexcontainer">

  <div class="photo-container">
    <img src="https://media2.giphy.com/media/kiXLfqncf42kg/200_s.gif" class="front">
    <div class="back">
      Christmas tree
    </div>
  </div>
  
   <div class="photo-container">
     <img src="http://hdwallpaperpoint.com/wp-content/uploads/2016/05/Happy-birthday-candles-on-cake-small-cake-hd-4k-wallpaper-300x200.jpg" class="front">
    <div class="back">
      Happy Birthday
       </div>
       </div>
  
  <div class="photo-container">
    <img src="https://www.walldevil.com/wallpapers/a76/thumb/halloween-jack-o039-lantern-pumpkin-ghost-cat-skull-spider.jpg" class="front">
    <div class="photo-desc back">Halloween
    </div>
  </div>
  
  

</div>

This approach gives a nice 'fade in' effect which complements the animation well. I've also ensured that the images remain visible when hovered over, rather than disappearing on the flip side.

On a side note, it's a bit disappointing to see that others came up with a solution before me :)

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

Ensuring Consistent Placement of Elements Regardless of Screen Size with CSS

I'm currently working on an Ionic App and I need to position some buttons (stacked vertically) at the bottom-left corner of the device's screen. Here is the CSS I am using: .button { left = "1em"; z-index = "13"; overflow = "scroll"; ...

What is the best way to deactivate the second selection option?

<select id="title0"> <option value="0">--- disable</option> <option value="1"> books</option> </select> <button id="save" type="submit">Save</button> <select id="title1"> <option value="0"& ...

Reloading a webpage does not clear HTML tables containing jQuery interactions in Firefox

Apologies if this question has already been asked. I incorporated hide/unhide features using jQuery into a simple HTML table. The table functioned correctly in Chrome 24.0.1312.52 m and IE8+. Yet, upon refreshing the page in Firefox 15.0.1, the pr ...

Retrieve the AngularJS scope object by using an alternate scope object as the identifier

As I loop through an array of person objects using ng-repeat, imagine the array looks something like this: [{ "display_name": "John Smith", "status": "part-time", "bio": "I am a person. I do people stuff.", }, { "display_name": "Jane Doe", "stat ...

Stylesheet specific to Internet Explorer not loading

My Rails application (link) is experiencing display bugs in Internet Explorer. I am trying to fix these bugs by making changes in the app/views/layouts/application.html.haml file where I have included: /[if IE] ...

Need to split your screen into two horizontal DIVs, each with their own scrollbars? Check out this example link for a demonstration!

Hey there! I have a question about creating something similar to this cool website: I'm working with Wordpress and using a child theme for my website. I want to include a fixed header as well. Currently, I've managed to give each div its own sc ...

The background color spills outside the column when using 100% width

Bootstrap 5 is being used, and two columns have been created on the page. The current output looks like this: https://i.stack.imgur.com/P6oZs.png Now, there's a need to display an orange color from end to end of the left column. To achieve this, h- ...

Using HTML and CSS to create a display-table for laying out a form

Working on a dynamic HTML/CSS layout that simplifies the process by using classes like form, row, cell label, and cell input to control elements (width, alignment, etc.). I decided to utilize display: table along with its child elements table-row and tabl ...

modify brand information through the use of javascript and customizable settings

In the default setting, I want all product details to be displayed. If the option value matches the product's brand name (b_name), then I want to display the corresponding details. Let's consider a list of products with their details: Samsung ...

Obtaining the date input value from the ng2-date-picker component in Angular2

I am struggling to extract the value from a date picker input field (ng2-date-picker). Despite attempting various methods to retrieve the value, I have not been successful. For reference, here is the link to the npm package I am utilizing. This represent ...

Unusual actions from the jQuery Steps extension

I am currently utilizing the jQuery Steps plugin (FIND IT HERE). The issue I'm facing lies within an IF statement that is causing the wizard to return to the first step instead of staying on the current indexed step. While all other IF statements are ...

Changing the style of a single element in various components in Vue

I need to alter the design of a specific div that is used in different components within my Vue.js application. The #app div should have a padding of 172px only in the Hello.vue component, while it should remain at 0px in all other components. Is there a w ...

Creating a non-editable form or text field upon clicking the Submit button

<form [formGroup]="calculateForm"> <div class="form-group row"> <p for="inputFrom" class="col-sm-4">Distance traveled ...

Ways to connect css file to ejs views in nodejs

Currently, I am tackling a beginner node.js server project. While I have successfully managed to render dynamic HTML using ejs templates, I seem to be facing difficulties when it comes to linking CSS styling to these templates. In an effort to address thi ...

Begin counting starting from 1 all the way up to 24, then feel free

I've developed a counter that increments from 0 to 24, and once it reaches 24: setInterval(function(){DayAndNight()}, 1000); var iState = 12; function DayAndNight() { //console.log('test'); switch(iState) ...

Looking to show a div upon clicking a link with the use of Javascript

Looking for a workaround due to restrictions on using alert or any Js dialog box, I need to create some sort of magic trick: 1. Create a div with a link named "info". 2. Develop an invisible div that will serve as my "PopUp" containing random information. ...

Is your dropdown menu malfunctioning with jQuery? (Chromium)

I am currently working on a website that requires the options in the second dropdown menu to change based on the selection made in the first dropdown menu. However, despite the fact that the browser is recognizing the javascript file, it doesn't seem ...

Concealed text hidden beneath a Sticky Navigation Bar (HTML/CSS)

I'm in the process of creating a simple website that includes a sticky Navigation Bar. However, I'm encountering an issue where text added to the website is being hidden behind the Navbar. Is there a way for me to adjust the positioning of the te ...

Adjust the quantity by clicking or typing

Hey there! How's it going? I'm curious to learn how I can enable the user to manually input the quantity in the field, in addition to using the plus and minus buttons. Essentially, is there a way for the user to type in the number of items they ...

How can a CSS class be inherited from a different file?

I have defined a class for styling a button: .client-header button { /*Properties*/ } And I also have a class to indicate when the menu is open: .client-menu-open { /*Properties*/ } My goal is to change the background of the button depending on ...