Transitioning CSS - An elegant way to display div contents

Here's the concept: A hidden div that slides down, pushing other content, when a button is clicked. Clicking the button again will hide the div and raise the other content.

HTML

<div id="topDiv" class="hidden">
    Some content<br>
    More complex content
</div>
<button id="thebutton" onclick="toggle('topDiv');">Toggle the div</button>
<div id="bottomDiv">
    Some content<br>
    More content!<br>
    Even more content!<br>
</div>

CSS

div.hidden {
    height: 0px;
}
div {
    height: 400px;
    transition: height 0.5s;
}

Javascript

function toggle(someId) {
    var someElem = document.getElementById(someId);
    someElem.className = someElem.className == 'hidden' ? '' : 'hidden';
}

The current issue is that the content of the hidden div is still shown. If I change div.hidden to have display: none; or visibility: hidden;, the "sliding" effect is lost.

I'm looking for a solution without using jQuery.

Answer №1

Ensure to include overflow:hidden within the div element.

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 Hamburger Menu in the Bootstrap Navbar is failing to collapse

My website uses Bootstrap v5.3 and I've added a navbar, but the hamburger icon is not collapsing on mobile devices when clicked. Can someone please review my code to see if there are any issues? I can't figure out what's wrong. <!DOCTY ...

The execution of the Ajax success call is failing to take place

Looking at my recent AJAX call, I realized there might be an issue with how I'm sending the parameters. $.ajax({ type: "POST", url: "Default.aspx/GeneratePdfs", data: '{frequency: "' + $('#ddlReportFrequenc ...

Dispatch is functioning properly, however the state remains unchanged

I'm currently developing an application that utilizes redux for state management. In a particular scenario, I need to update the state. Here is how my initial state and reducer function are set up: import { createSlice } from '@reduxjs/toolkit&a ...

activate the button once valid input has been provided

How can I enable a button based on the amount entered? Let's say there is a minimum of 100 and a maximum of 200. If the user enters an amount below 100, display an error message and keep the button disabled. If the user enters an amount above 200, ...

Erase jQuery from the text

I am struggling with splitting or removing text from a filename. For example, if I have filenames like: 200726100_50-0002.JPG 230514008_60-0001.JPG The desired result should be: 230514008_60.JPG 200726100_50.JPG Am I not using the split function cor ...

Eliminate a span element in Android when the content within the span is modified

Imagine I write a comment like this: Hey Sarah, take a look at this.... In this message, I want to emphasize Sarah. However, whenever I modify the name Sarah or delete even one letter, the span changes. The issue lies in my usage of spannableString.setSp ...

The act of initiating a click on a radio button involves evaluating conditions prior to toggling

Apologies for the slightly ambiguous title, let me provide a clearer explanation. I have created a codepen to demonstrate an issue that I am facing. You can view it here. In my codepen, I have two toggle buttons labeled "Male" and "Female" for simplicity. ...

Arranging a collection of objects (Displaying information in a random sequence)

Here is a summary of the data returned in a shortened version: var array = [{ "response": { "itineraries":[ { "price": { "totalPricePerPassenger":"104" ...

Incorporating the latest version of SMINT into your Shopify store

Appreciate the help you're about to give. Here's the process of incorporating Smint v3.0 into Shopify: Added jquery.min.js and jquery.smint.js to asset files Inserted the following code within the tag of theme.liquid {{ 'jquery.mi ...

What is the best way to prevent the body from scrolling when scrolling on a fixed div without making the body's scroll bar disappear?

Is there a way to prevent the body from scrolling while I scroll on a fixed div? I attempted using overflow:hidden for the body, which stops scrolling but causes the page to shake when the scroll bar disappears. Is there a solution that allows me to keep ...

Enhancing the style of the top menu Index by applying a border-bottom effect when hovering over it in a CSS Horizontal Drop Down Menu

I'm having trouble adding a border-bottom: 1px solid #FFF to all the top menu (index) items when they are hovered over. Can anyone help me with this? #menu{ padding:0; margin:0; position: fixed; top: 30px; left: 0px; font-size ...

Having trouble adjusting the outer margin of a PDF generated with html/css in a Flutter iOS app

I am currently facing an issue with the PDF generated from Html/css in my flutter iOS app. While the layout appears fine on Android, there seems to be a problem with left margins when it comes to iOS, as illustrated in the attachment provided. For referen ...

Issue with Flowtype not properly refreshing when maximizing or minimizing

There is a strange behavior with my Flowtype plugin. When I load the page without maximizing the screen, the font size remains the same even after maximizing the screen. However, if I then restore the window to its original size, the font size adjusts as ...

Encountered an issue while attempting to integrate Nebular into my Angular application

As a newcomer to Angular, I decided to try installing Nebular using the command ng add @nebular/theme. However, I encountered an error in the process. Upon entering the command into my terminal, the following error message appeared: ? Which Nebular theme ...

"Enhance User Experience with jQuery Autocomplete using String Arrays

Within my web form model (AdtFormModel), there is a variable: public List<String> TemoinsVille { get; set; } I opted for a list structure as I intend to allow users to dynamically add more 'TemoinsVille' inputs in the form. Currently, ...

Scraping Websites with SimpleHTMLDom in PHP

I am struggling to extract specific data from a table on a website page, particularly the columns name, level, and experience. The table's alternating row colors (zebra pattern) are complicating this task. I have implemented SimpleHTMLDom for this pu ...

Display a popup on a button click or icon click in ASP.NET

On Facebook, you may notice that you have 4 friend requests or notifications in the small mail icon on the right side. When you click on it, a pop-up appears with an accept button, and once you accept, it disappears and the remaining three requests are sho ...

When an li element is styled with a width of 50% and floated to the left, it does not display the bullet points

When attempting to create a 2-column list, I implemented the following CSS: ul { overflow: hidden; } ul li { float: left; width: 50%; } However, I noticed that when I have 2 items in the list, the one on the right displays a list bullet while th ...

Creating a collection of interconnected strings with various combinations and mixed orders

I am currently working on creating a cognitive experiment for a professor using jsPsych. The experiment involves around 200 logical statements in the format T ∧ F ∨ T with 4 different spacing variations. My main challenge is to figure out a way to a ...

The grpc client is not able to receive the data being streamed from the

I've been attempting to stream the output of a nodejs child process through grpc, but I consistently receive an empty result. Here is my proto file: syntax = "proto3"; package servicePackage; service Mobile { rpc sign(Empty) returns ( ...