Transition property in CSS not functioning properly

In my webpage, I have div elements with multiple classes for easy manipulation in jQuery based on their nature.

When I try to expand and collapse the div on a button click event, everything works fine except for the transition effect which is not working as expected.

To see an example of this issue, you can check out the Fiddle I created by clicking here.

I've seen examples of using transition, but I'm wondering if the transition should always be applied to top-level identifiers like div or element-id.

This is how my CSS looks like (also available in the fiddle):

.display{
  background-color: #a17917;
} /* DIV */
.mytable td div.data-div{
    min-height:120px;
    max-height:140px;
    min-width:120px;
    max-width:140px;
    border: 1px solid black;
    overflow:hidden;
    position: relative;
    transition: height 3s, width 3s;
}
.mytable td div.collapse{
   min-height:120px;
    max-height:140px;
    min-width:120px;
    max-width:140px;
}
.mytable td div.expand{
    min-height:300px;
    max-height:300px;
    min-width:300px;
    max-width:300px;
}

On button click, I simply add the expand class to the div and remove the collapse class (after checking if the div is already expanded or not).

Answer №1

Give this a shot:

.display{
  background-color: #a17917;
}
.mytable td div.data-div{
    min-height:120px;
    max-height:140px;
    min-width:120px;
    max-width:140px;
    border: 1px solid black;
    overflow:hidden;
    position: relative;
    transition: all 3s;
}
.mytable td div.collapse{
   min-height:120px;
    max-height:140px;
    min-width:120px;
    max-width:140px;
}
.mytable td div.expand{
    min-height:300px;
    max-height:300px;
    min-width:300px;
    max-width:300px;
}

Check out the demo here

Answer №2

Your current CSS code includes a transition for the properties height and width, even though those properties are never changed. One simple solution is to add a transition for all properties instead.

transition: all 3s;

Visit this link to see the updated code in action

Answer №3

DEMO

.mytable td div.data-div{
    min-height:120px;
    max-height:140px;
    min-width:120px;
    max-width:140px;
    border: 1px solid black;
    overflow:hidden;
    position: relative;
    transition: all 3s ease /* modify this */
}

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

Highlight the menu when the user is actively browsing this section

I have successfully implemented a fixed and sticky menu with a progress bar that resembles an underline. However, I am facing an issue with positioning the progress bar correctly under each menu section. For example, when a user hovers over the first secti ...

What is the best way to pass value to a URL in a React JS application?

Is there a way to properly use history.push in React to push text to the URL route manually? I am trying to achieve this in my onChange method for an input field: function Header(props) { return ( <div> <input type="radio" onChan ...

The step-by-step guide for replacing the extJs Controller component

I have developed a versatile component that is being utilized across different products. In this case, I have a generic window and window controller which I am customizing to fit our specific product requirements. This is my generic window: Ext.define(&a ...

Obtain the latest NPM package versions

I am currently seeking a way to compile a comprehensive list of all major versions that have been released for a specific NPM package. By utilizing the following API link, I can retrieve a list of available versions which includes both the major and exper ...

What is the best way to extract an object by its specific id using json-server?

I am attempting to retrieve an object by its id using json-server. If I only return a single variable (one JSON) in the module.exports of the database file, everything works fine. However, if I try to return an object with multiple variables, I encounter a ...

Tips for retrieving a value from an async function called within the .map function in React?

After doing some research, I discovered that async functions return a promise whose result value can be accessed using .then() after the function. This is the reason why it's not rendering properly. My question is: how can I render the actual value fr ...

The issue of VueRouter malfunctioning in history mode within Wordpress

I have integrated Vue into my Wordpress theme, but I am facing an issue with the router when setting mode: 'history'. The site goes blank and even after trying to configure the .htaccess file, nothing seems to work. My project is located in the V ...

Allow the table headers to be flexible and accommodate extended names in the rows

<div class="container"> <div class="table-responsive"> <table class="table" width="100%" > <thead> <tr> <th class= "style6" >Year</th> <th class="styl ...

What is the best way to set breakpoints on Material UI components?

Currently, I am exploring material-ui and I'm curious if there is a way to set all breakpoints at once. The code snippet below seems quite repetitive. Is there a more efficient method to achieve this? <Grid xs={12} sm={12} md={12} lg={12} xl={12} ...

Problem with Masonry.js only occurring on live WordPress website, not on local development site

I have been working on the following website: This website is built using a Wordpress theme with Masonry.js integration. After downloading and cloning the site's database, I noticed that it displays perfectly on my local MAMP Pro environment. Howev ...

Styles not applied to React.js components when page is refreshed

I'm encountering an issue while using React in combination with react-router and material ui. Upon the initial page load, everything appears as expected. However, if I refresh the page, all styles seem to disappear. If I make changes to the code and ...

How to easily align an image and blockquote vertically in CSS with automatic width for the blockquote

I am struggling with a layout issue involving a list of items containing images and blockquotes. My goal is to set a maximum width for the images and have the blockquotes automatically adjust their size to fit next to the images, all while keeping both ele ...

Mastering the art of incorporating background image transitions and creating a seamless slider for navigation

Is there a way to create a navigation menu like the one on this theme? On this theme, when you hover over a menu item, the background image smoothly moves left or right to the item you are hovering on. If anyone knows of plugins that can achieve this eff ...

Guide on integrating the *Remember me* feature with the Amazon Cognito sdk

Seeking to incorporate a Remember Me feature for authentication process in an Angular2 project utilizing amazon-cognito-identity-js. Check out the details for this implementation at this issue link. Overview of current authentication procedure If the us ...

Issue with reactivity not functioning as expected within VueJS loop without clear explanation

Struggling with implementing reactivity in vue.js within a loop? The loop renders fine, but firing an event updates the content without visibly rendering the data on the page. The latest version of vue.js is being used with bootstrap and jquery. Despite a ...

JavaScript time zone error specific to Internet Explorer

In my code, I am attempting to retrieve the timezone name or ID based on the client's local time. When testing with clients from the United States, I correctly receive EDT. However, when trying the same code with clients in the Indian timezone, it ret ...

Error message: "Despite using the 'use client' function in Next.js, a ReferenceError occurs as 'window' is undefined."

What is the reason for the server running this hook when "use client" is included? It does not lead to any application crashes, everything functions with no errors, but an error is logged at the const [windowWidth, setWindowWidth] = useState(window.innerWi ...

Partial view could not be loaded through ajax request

I am trying to dynamically load data from a partial view into a div when a hyperlink is clicked. However, despite writing code to call an action that returns the partial view, I am having trouble actually loading it. Below is my Index.cshtml code: @mode ...

What is the method for incorporating a currency symbol into a jQuery mask?

I have successfully implemented the mask on the <td> element of the table, but now I would like to include the currency symbol before the value as shown in the example below. if ($(this).attr('title')==='Value') { $(+ ...

What are some creative ways to represent data using different numerical intervals?

Looking to develop a visualization of a .CSV file containing 1.2 million lines, showcasing addresses in the format: source , destination 12.251.512 , 12.623.743 51.734.312 , 23.233.991 6334.6231.123 , 42.532.54453 (utiliz ...