Is your max-height transition not functioning properly?

  1. Is there a way to create a collapsible panel using only CSS similar to the Bootstrap bootstrap collapse panel?

  2. Why isn't the max-height transition working for me?

  3. How can I toggle the panel if it's checked, and have the panel collapse when double-clicked?

  * {
    padding: 0;
    margin: 0;
  }
  
  .content {
    width: 400px;
    height: 300px;
    background: #ccc;
    margin:40px auto;
    border:1px solid #eee;
  }
  label{
  padding:10px;
  }
  .content>div{
  width:100%;
  transition: all ease 1s;
  }
  p{
    word-break: break-word;
    height: 0%;
    overflow: hidden;
    max-height: 0;
    transition: max-height ease 1s;
  }
  input[type=radio]{
  transition: all ease 1s;
  -webkit-appearance:none;
  }

  label:hover+input+p{
max-height: 100%;
  }
<div class="content">
    <div>
      <label for="demo1">demo1</label>
      <input type="radio" name='demo' id='demo1'>
      <p>dsfjhbklweji;dfsfjhbk lwedsfjhbklweji;df sfjhbklweji;dfovjji;dfovj</p>
    </div>
    <div>
      <label for="demo2">demo2</label>
      <input type="radio" name='demo' id='demo2'>
      <p>ewrsds fjhbk lweji;dfsfjh bklwedsfjhbkl weji;dfs fjhb klweji;df ovj ji  ;dfokj</p>
    </div>
    <div>
      <label for="demo3">demo3</label>
      <input type="radio" name='demo' id='demo3'>
      <p>sdjkassfjhbklweji;dfsfjhbklwedsfjhbklweji;dfsfjhbklweji;dfovjji;dfodlnjk</p>
    </div>

Check out this demo on JSFiddle

Answer №1

Upon each activation of the radio:checked function, you have the ability to apply a transition effect to the p tag for adjusting the opacity and height. The code snippet below illustrates this process:

The addition of the plus + selector allows for the selection of all individual elements following the input element, such as the placement of p after input.

Utilizing the max-height property sets the maximum height of an element, restricting the value of the height property from exceeding the specified max-height value.

.content{
  width:400px;
  height:400px;
  border:1px solid #ccc;
  margin:auto;
}
p{
  height:0px;
  opacity:0;
  word-break:break-word;
  transition:all 0.6s ease;
}
input[type="radio"]{
  -webkit-appearance:none;
}
input[type="radio"]:checked + p{
  height:50px;
  opacity:1;
}
<div class="content">
    <div>
      <label for="demo1">demo1</label>
      <input type="radio" name='demo' id='demo1'>
      <p>dsfjhbklweji;dfsfjhbk lwedsfjhbklweji;df sfjhbklweji;dfovjji;dfovj</p>
    </div>    
    <div>
      <label for="demo2">demo2</label>
      <input type="radio" name='demo' id='demo2'>
      <p>ewrsds fjhbk lweji;dfsfjh bklwedsfjhbkl weji;dfs fjhb klweji;df ovj ji  ;dfokj</p>
    </div>
    
    <div>
      <label for="demo3">demo3</label>
      <input type="radio" name='demo' id='demo3'>  <p>sdjkassfjhbklweji;dfsfjhbklwedsfjhbklweji;dfsfjhbklweji;dfovjji;dfodlnjk</p>
    </div>

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

Ways to increase the font size of input text using bootstrap's css framework

I currently have a bootstrap textbox set up like this: <input type="text" class="span9" required name="input_text"/> My goal is to increase the height of my input box to 300px. The width, on the other hand, is being handled by span9. I utilized In ...

Fading colored images and backgrounds using Javascript

Although js and html are not my strong points, I am attempting to create two simple effects on a single page. As the user scrolls down the page, I want the background image or color to change as different divs come into view and then move off the screen. ...

jquery fails to alter label:before

I have encountered a peculiar issue with jQuery and labels. It's quite strange because everything seems to work fine when I change the background color of a label or its font-weight, but using the :before selector doesn't seem to work. Any thoug ...

challenges with website design on Internet Explorer 7

Welcome! This is my HTML code: <div style="width:220px;float:left;" id="radio_text"> <ul style="width:20px;float:left;display:block;"> <li style="list-style:none;line-height:13px;height:13px;float:left;"><input type="radio ...

Exploring the implementation of if/else statements in Sass/HTML

I need assistance with customizing the appearance of a save button on my form. The button is currently disabled and appears in blue color, but I would like it to change to a different color until all fields within the form are completed. Even though it c ...

Fade in and fade out elements with jQuery using opacity in Internet Explorer

I have encountered an unusual issue in Internet Explorer involving a CSS Overlay used for a lightbox. The problem arises when I apply the fadein and fadeout effects using jQuery - everything seems to work smoothly except in IE. Instead of displaying a smo ...

CSS Sprite Animation Technique

Hello there, I've been attempting to create a simple animation using CSS and a sprite but for some reason it's not working. Can anyone help me figure out what I'm missing? I have created a sample on JS Fiddle. Could someone please explain w ...

Troubleshooting CSS Display Problem on Chrome and Firefox

While working on the design of a website offline, everything seemed to be running smoothly. However, upon uploading it to the server, various issues began to arise. Initially, the file loaded correctly upon first visit. Unfortunately, after reloading the ...

Limiting zero is ineffective when it comes to pop-up issues

Hey there, I'm looking to prevent users from inputting zero and dot in a specific field, which is currently working fine. However, when the field is within a pop-up, the code below doesn't seem to work. <script> $('#name').keyp ...

Alter the background-color of the parent div when an input is checked using CSS

.chk-circle { width: 8px; height: 8px; background: #afb0b5; border-radius: 100%; position: relative; float: left; margin-top: 4px; margin-right: 8px; } .chk-circle label { display: block; wi ...

Each div will display the same image twice when loading the image

I have a grid where images are dynamically loaded with a link to a lightbox. Currently, this is how I am achieving it: $(".selection_thumb").each( function(i) { $(this).append("<a data-lightbox='image-1' href='img/folder/folder/"+(++ ...

Microsoft Edge and Google Fonts display strong and distinctive lettering

When using Microsoft Edge on Windows 10, all text appears with bold UTF-8 characters: https://i.sstatic.net/JfN0S.png I'm unsure of what the issue is. Is there a solution available? ...

Simple HTML alignment tool instead of Bootstrap

Are there any other options besides Bootstrap for a predefined CSS library that can help align and customize an HTML page quickly? I have been using ASP.NET and Bootstrap for my development, but I'm looking for something new. If there is another libr ...

Tips for eliminating white frames or borders on the Mapbox canvas map

In my current project using Angular 10, I have integrated Mapbox to display path routes. Following the standard Angular practice of splitting components, I separated the map rendering component and called it into the main map component. However, I encounte ...

Styling Options for Material-UI Tables: Enhancing the Look of Your Table Components

I am working with 'material-ui' and attempting to change the color of a table element based on its value. In the code snippet below, I have tried to make the background color go red if the cell value is "Out of Zone". However, even though the tab ...

Halt hovering effect after a set duration using CSS or Vanilla JavaScript

Looking for a way to create a hover effect that lasts for a specific duration before stopping. I want the background to appear for just 1 second, even if the mouse remains hovering. Preferably using CSS or JavaScript only, without jQuery. To see my curren ...

Align columns to the right and left using Bootstrap

It should be simple enough, but I can't seem to find my mistake. Goal: The entire markup should be centered with a width of col-10. Within the same 10-column width, there should be two divs each taking up 50% of the space. Using Bootstrap 5, for so ...

The Bootstrap nav-tab functions perfectly on a local server, but unfortunately does not work when hosted remotely

UPDATE: Issue resolved so I have removed the Github link. It turns out that Github pages require a secure https connection for all linked scripts. Always remember to check the console! I encountered an unusual bug where the Bootstrap nav-tab functionality ...

Expand the image size when hovering using CSS

I want to make a simple image link button that enlarges when I hover over it. The code below accomplishes this, but I also want to move the paragraph when the image gets larger. Any suggestions on how I can select and move the paragraph when I hover over ...

Animation event in CSS3 fails to trigger on Firefox browser

Exploring the potential of CSS3 animation to detect when an input transitions from the enable to disable state, I encountered a challenge specifically in Firefox. Here is the code snippet that showcases the issue: View Demo on jsFiddle HTML: <input t ...