Vertical CSS accordion that flips when hovered within an unordered list

TASK
- Flip accordion title divs vertically when hovered over.
- Ensure frontface and backface display the same text and color, but with different background colors.

ISSUE
- I have successfully implemented a horizontal flip effect, but I am struggling to apply it to a ul structure. The front text is appearing upside down after the vertical flip animation.

REFERENCE
http://jsfiddle.net/zuhloobie/21b2r35n/

THEORY
- Before the existing code in the fiddle:
(1) It might be necessary to place

<div class="vFront">text</div>
and
<div class="vBack">text</div>
within the <li> elements to control front and backface visibility. Implementing this breaks the animation and design.
(2) After attempting (1), adjusting the jQuery code to target the <a> elements for proper animation (expansion/contraction) does not seem to be effective. This could be the root of the issue.

Any insights on how to overcome this challenge?

Answer №1

To flip the li vertically by 180° without flipping the text, simply add scaleY(-1) to the transform property:

.vertical.vFlipContainer:hover .vFlipper {
  transform:rotateX(-180deg) scaleY(-1);
}

The background of the a element may not change instantly due to a few reasons such as the padding on its parent li and potential interference from the animation timing on its hover style.

To address this issue, let the li control the background style change. Remove the background-color property from

#drawer.courseDrawer > ul > li > a
and use the following styles:

.vertical.vFlipContainer .vFlipper {
  transform-origin:100% 50%;
  background-color:#FF8000;
}

.vertical.vFlipContainer:hover .vFlipper {
  transform:rotateX(-180deg) scaleY(-1);
  background-color: #999999;
}

Check out the Working Fiddle for a demonstration.

Answer №2

Adjust the hover effect to rotate by -360 degrees

.vertical.vFlipContainer:hover .vFlipper {transform:rotateX(-360deg);}

http://jsfiddle.net/21b2r35n/1/

Answer №3

While this solution may not be the most compact, it will fulfill your requirements precisely. In the original design, only the title bar is gray when hovered over, but the bar is flipped when the expanded content is hovered over. My variation ensures that the title bar's color remains changed throughout the flipping of the bar, not just when hovering over it.

Adjusted CSS:

/* MISC ---- */
@import url('http://fonts.googleapis.com/css?family=Open+Sans');
body {font-family: 'Open Sans', sans-serif; font-weight:300; letter-spacing:1px; color:#4D4D4D; padding-top:0px; }
.blackColor {color:#000000 !important;}
.grayColor {color:#999999 !important;}

/* ACCORDION GENERIC ---- */
#drawer {width:100%; text-align:left; margin-top:20px;}
#drawer ul { list-style:none; padding:0;}
/*hands*/
#drawer > ul > li.has-sub > a:before {font-family:FontAwesome; content:'\f0a7 \00a0';}
#drawer > ul > li.has-sub.active > a:before {font-family:FontAwesome; content:'\f0a6 \00a0';}
/*text*/
#drawer ul ul li:nth-child(even) {padding-left:60px; font-size:14px; color:#999999; line-height:24px;}

/* ACCORDION SPECIFIC ---- */
/*title*/
#drawer.courseDrawer > ul > li > a {font-size:16px; display:block; color:#FFF; margin-top:20px; padding:10px; text-decoration:none; line-height:20px;}
#drawer.courseDrawer > ul > li > a:hover {text-decoration:none; color:#FFF;}
/*heading*/
#drawer.courseDrawer ul ul li:nth-child(odd) {padding-left:30px; font-size:14px; color:#000000; line-height:18px;}
/*dropdown*/
#drawer.courseDrawer ul ul {display:none; list-style:none; padding:10px 0 20px 0; margin:0 0 20px 0; border-left:1px solid #FF8000; border-right:1px solid #FF8000; border-bottom:1px solid #FF8000;}

/* VERTICAL FLIP ---- */
.vFlipContainer {perspective:1000px;}
.vFlipContainer, .vFront, .vBack {width:100%; height:auto;}
/* flip speed */
.vFlipper {transition:0.3s; transform-style:preserve-3d; position:relative;}
/* hide back */
.vFront, .vBack {backface-visibility:hidden; -webkit-backface-visibility:hidden;}
/* front */
.vFront {z-index:1; background-color:#FF8000; color:#FFF;}
/* back */
.vBack {transform:rotateX(-180deg); background-color:#4FAEDD; color:#FFF; animation:vtoFront 0.3s linear normal forwards;}
.vertical.vFlipContainer {position:relative;}
.vertical.vFlipContainer:hover .vBack {animation-delay:0.3s; animation:vtoBack 0.3s linear normal  forwards;}
@keyframes vtoBack {  
  0% {z-index:0;}
  100% {z-index:1;}
}
@keyframes vtoFront {
  0% {z-index:1;}
  100% {z-index:0;}
}
.vertical.vFlipContainer .vFlipper {transform-origin:100% 50%; background-color:#FF8000;}
.vertical.vFlipContainer:hover .vFlipper {transform:rotateX(-180deg); background-color:#999999;}

.accTitle {
    position: absolute;
    background: transparent !important;
    top: -20px;
    left: 0;
    right: 0;
}

Edited Accordion Item:

            <li class="vertical vFlipContainer" ontouchstart="this.classList.toggle('hover');">
                <a class="vFlipper" href="#" onclick="return false;"></a>
                <a class="accTitle" href="#" onclick="return false;">ACCORDION 1 TITLE</a>
                <ul>
                    <li>Accordion 1 Heading</li>
                    <li>Accordion 1 Text 1<br>Accordion 1 Text 2</li>
                </ul>
            </li>

This solution provides a quick fix and ensures that the text does not flip more than the set -180deg.

The adjustment made involves removing the background-color from

#drawer.courseDrawer > ul > li > a
and
#drawer.courseDrawer > ul > li > a:hover
, and adding it to
.vertical.vFlipContainer .vFlipper
and
.vertical.vFlipContainer:hover .vFlipper
respectively. This change allows the background color to transition at any point during hovering. Additionally, the extra class and anchor prevent the text from flipping.

JSFiddle: http://jsfiddle.net/zbg15rbx/

I trust this information is beneficial. ^^

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

The data retrieved from the $.ajax() request in Vue.js is not properly syncing with the table

After setting up an $.ajax() function and ensuring the data binding is correctly configured, I expected the data to append to a table on page load without any issues. However, the data is not appearing as expected. Is there something that I might be overlo ...

Can you explain the function of mdLiveAnnouncer in Angular Material and how it operates?

Could someone provide an explanation of $mdLiveAnnouncer using this code snippet? module.controller('AppCtrl', function($mdLiveAnnouncer) { // Making a basic announcement (Polite Mode) $mdLiveAnnouncer.announce('Hey Google'); // ...

Code to conceal navigation bar...positioned neither at the top nor at the bottom of the scroll

As a graphic designer with some coding knowledge, I'm struggling with a particular issue... I have a traditional navigation bar that only appears when the user scrolls down a bit, which I achieved through JavaScript. However, I want this to occur onl ...

Guide on darkening the surrounding div of an alert to give it a modal-like effect

I want to display an alert to the user in a visually appealing way. To achieve this, I am utilizing Bootstrap's alert class. Here is how I am showing the user a div: <div class="alert alert-warning alert-dismissible" role="alert"> Some text ...

Element after jquery.load()

I am currently working on implementing ajax in WordPress using the jQuery.load() function. However, I have encountered an issue as Isotope does not seem to work after the page loads. Any suggestions on how to resolve this problem are greatly apprecia ...

Is there a substitute for image cropping aside from the CSS clip property?

Looking to create an image gallery where thumbnails are cropped to 150px x 150px, but struggling with non-square rectangular images of various sizes. Adjusting width and height distorts the images. Are there alternative CSS or jQuery options for cropping ...

Exploring the integration of JSONP with the unmatched features of Google

I am attempting to utilize the Google maps directions API by using jquery $.ajax. After checking my developer tools, it seems that the XHR request has been completed. However, I believe there may be an issue with the way jquery Ajax handles JSON.parse. Y ...

Error: Uncaught ReferenceError: d3 is undefined. The script is not properly referenced

Entering the world of web development, I usually find solutions on Stack Overflow. However, this time I'm facing a challenge. I am using Firefox 32 with Firebug as my debugger. The webpage I have locally runs with the following HTML Code <!DOCTYP ...

The elements are stacked on top of each other, but unfortunately, the scroll

While scrolling the page, I encounter a small issue where the elements stack on top of each other. Additionally, when I perform a search, the elements move with the keyboard. I have attached screenshots to illustrate the problem. My goal is to have the cat ...

Using jQuery to retrieve an AJAX response and save it into a variable

I am looking to save the data retrieved from into a variable and access info.h. I attempted the following: $.ajax({ async: false, type: "GET", url: "http://www.youtube-mp3.org/a/itemInfo/?video_id=Vd85aPZ-QAE&ac=www& ...

Javascript unable to update the DOM

I've been working on a project to prototype a simple functionality using JavaScript for learning purposes. However, I've encountered an issue where the contents within the <p> tag are not updating, and I'm currently stuck. Here's ...

Looking to manipulate HTML elements using HTMLAgilityPack in C#? Let's explore how it can be done

Let me outline the situation at hand: <a href="test.com">Certain text <b>is bold</b> while some is <b>regular</b></a> So, my question is this: how can I extract the "test.com" section and the hyperlink from the text, w ...

Chrome experiencing problems with placeholder text fallback event

My text field has a placeholder text that says "First Name". When the user clicks on the field, the text disappears and allows them to type in their own text. HTML <input class="fname" type="text" placeholder="First Name"/> JS function handlePlac ...

How to retrieve and delete a row based on the search criteria in an HTML table using jQuery

Here is the HTML code snippet: <table class="table" id="myTable"> <tr> <th>Type</th> <th>Counter</th> <th>Remove</th> <th style="display:none;">TypeDistribution</t ...

Using jsPlumb to Access an Element After a "Mouseup" Event has Completed

$(document).on('mouseup', '.agent-wrapper', function(info){ console.log(info); // Everything is working fine console.log(this); }); .agent-wrapper represents an element-wrapper for all jsPlumb objects. $(document).on(' ...

Implementing an onclick event listener in combination with an AJAX API call

I'm really struggling with this issue. Here's the problem I'm facing: I have a text area, and I need to be able to click on a button to perform two tasks: Convert the address text into uppercase Loop through the data retrieved from an API ...

Attempting to create a footer design featuring buttons aligned to the left and right sides

I am trying to create a layout similar to the bottom of Google's homepage using this code. However, no matter what I try, the "lists" are still appearing vertically instead of horizontally. My goal is to have three columns of links positioned side by ...

When the screen size changes, the sidebar in Bootstrap 5 smoothly reveals hidden content

I've been working on a sidebar design and everything seems to be going well so far. However, I've encountered an issue that has been giving me trouble for days now. Whenever I display a new page and then resize the screen, the content of the page ...

Can you guide me on implementing an onclick event using HTML, CSS, and JavaScript?

I am looking for a way to change the CSS codes of the blog1popup class when the image is clicked. I already know how to do this using hover, but I need help making it happen on click instead. The element I want to use as the button; <div class=&quo ...

Extract content from an HTML element and transfer it to PHP

Alright, listen up. I've got a task at hand where I need to fetch some information from my database by calling a PHP page through a link (<a href='name.php'>). Let's just say the code is speaking louder than my words: <?php ...