Automatically adjust child height when hovering over the parent element

I am working on creating custom dropdown lists that are activated by hovering over them using CSS.

<div class="CusSelect">
     <p>Select from List</p>
     <ul>
        <li>Football</li>
        <li>Cricket</li>
        <li>Hockey</li>
    </ul>
</div>

You can view the full code and demonstration on JSFiddle http://jsfiddle.net/ZX8AK/ with the included CSS rules.

The issue I'm facing is that when hovering over the list, it immediately sets the height to auto instead of transitioning smoothly. I would like the height change to be animated.

Since the height will vary depending on dynamically added items, I need a solution that allows for smooth height adjustment without knowing the final value in advance, whether through JQuery or CSS.

To achieve an animated height effect, you can use the following CSS:

.CusSelect:hover > ul
{
     height:100px;
}

However, the challenge lies in not knowing the exact height beforehand, necessitating the use of auto for flexibility.

Answer №1

Based on the information provided, it seems like the solution I proposed earlier would be suitable for your situation. To accommodate for a potential increase in li elements, consider applying the height transition to the li rather than the ul.

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

Steps for making a dropdown input field:1. Start by defining a

Is there a way to design a dropdown input using CSS or any other method? Take a look at this image for reference: Any suggestions on how to achieve it? ...

Using Three.js to apply multiple images onto a sphere and have individual control over each one

I have a 3D sphere that I am looking to map an array of images onto. I want to be able to control each image independently, allowing for fading in and out of each image. To better illustrate my goal, I will provide an example image of what I am trying to a ...

Blurred entities aligning in front of one another (THREE.JS)

While experimenting with three.js, I encountered an issue with objects appearing fuzzy when they overlap. The distortion looks like this. Can anyone provide assistance with this problem? Below is the code I'm currently using: // Initializing basic o ...

Regular expression: Identify all instances of double quotes within a given string and insert a comma

Is there a way to transform a string similar to the following: ' query: "help me" distance: "25" count: "50" ' Into either a JavaScript object or a JSON string that resembles this: '{ query: "help me", distance: "25", count: "50" }' ...

Key-based user retrieval is unavailable in Express, "findAll" can only be done through email

I've created a straightforward Express/Pug application designed for searching users in a database by "email" or by "key". In this setup, each user is assigned a unique string as their key. The structure of my user model and index model files can be se ...

Using Vue.js to showcase images in a horizontal layout (5 images per row)

I am trying to retrieve images from the service and display them horizontally, with a total of 10 images. My goal is to show the first five images in the first row and the next five images in the second row. Here is my current attempt: <div style=" ...

The Angular function fails to execute when clicked

I am trying to trigger a new page launch when a cube is clicked using Angular. Unfortunately, my current code doesn't seem to be working as expected and nothing happens when I click the cubes. This makes me wonder if there is something wrong with my i ...

Why is Devtools displaying an unusual numerical value in the console window?

Below is the code I am currently executing in the console. // Utilizing arrow functions without parameters for enhanced readability setTimeout( () => { console.log('Executed first'); setTimeout( () => { // More nested code cons ...

Obtain a URL using JavaScript's regular expressions

Is it possible to use JavaScript regex to fetch the first function parameter? For instance, when I click on a tag in this page element, how can I extract the inline link? Here's an example: <li><a href="#blog" data-rel="clos ...

Expression fragment in Thymeleaf

In splitting my templates into head/main/footer parts using thymeleaf, I have found a method to include stylesheets and javascript on certain pages while excluding them from others. This is achieved through the use of fragment expressions outlined here. M ...

Connecting a specific entry in a data table with a corresponding web address

I have been working on a vue component that utilizes vue-tables-2. You can find the functioning example here. My goal is to link the edit href url to the entire row rather than just the edit cell. I attempted to achieve this using vanilla javascript by a ...

Having trouble retrieving input data in XML format, resulting in a TypeError: 'NoneType' object does not support item assignment

Can you please help me figure out what I did wrong? I managed to create data successfully in JavaScript, but whenever I try in Python, I keep encountering this error: getVals = list([val for val in partner_name[:25] if val.isalnum()]) #limit the domai ...

Executing an xajax/ javascript function simultaneously

Is there a way to simultaneously execute the same function? Here is an example: function convert_points() { show_loading(); xajax_ConvertPoints(); xajax_GetRegularGamingCards(); } When xajax_ConvertPoints is called, there seems to be a mill ...

How can I use PHP to send the $_POST array via ajax?

I am faced with a situation where I have multiple input fields named Change[xxx]. In the traditional way, when an update button is clicked, data is sent and the database gets updated. But how do I pass this Change[xxx] data using Ajax without relying on jQ ...

Hide elements in hidden divs until the page is fully loaded to reduce initial page

www.prismasites.com I am creating a unique world map by using SVG DIVs shaped like Continents. Upon clicking on a continent on the world map, it conceals the world map DIV and displays the respective continent DIV with SVG. I have successfully achieved ...

When the cursor hovers over the button, it

I'm looking to enhance the interactivity of my buttons so that they change color when clicked, but I am facing issues with the CSS pseudo-class .button:focus not working as expected. Below is the code snippet I am working with: ul { list-style-t ...

What is the best way to insert a <dv> element following a <Typography> component in the provided code?

After learning React, I have attempted in various ways to get this code snippet to work. I referred to a question on Stackoverflow as well as the HTML div documentation The goal is to have the text and link displayed in a horizontal line, not vertically s ...

Troubleshooting the sidebar pin-unpin problem using Jquery and CSS

I have created a single side panel that allows me to toggle between opening and closing the sidebar by hovering on it. I can also pin and unpin the sidebar by clicking on the pin image. Now, I want to open the sidebar onClick instead of onHover and remove ...

AppProps in Next.js - Ensure that you have the correct loader set up to handle this specific file type as there are currently no loaders configured for processing it

I've encountered an issue while working on a Next.JS 13.5.6 application in development mode. When I try to connect to the site, I receive an error message. However, everything works fine when I switch to production mode after building and starting the ...

Is it possible to retrieve a physical address using PHP or Javascript?

Is it possible to retrieve the physical address (Mac Address) using php or javascript? I need to be able to distinguish each system on my website as either being on the same network or different. Thank you ...