Expanding CSS transition for child elements as they increase in size

I am currently working with Vuetify and have encountered an issue with a v-list-item that contains a title and a subtitle. The problem is that the title is restricted to displaying only one line. If the title exceeds this limit, it gets cut off and shows "...". I would like the subtitle to disappear and show the full title when I click on the list item. This action may cause the entire v-list-item to increase in height. To ensure a smooth transition without any sudden jumps in height, I am looking for a solution to implement a gradual expansion effect. Unfortunately, I haven't been able to resolve this challenge yet, so any suggestions or ideas would be greatly appreciated. Here's my current code:

<v-list-item three-line :class="{ activeListItem: currentPostId === post.id }">
   <v-list-item-content>
      <v-list-item-title :class="{'full-text': currentPostId === post.id}">
         Title
      </v-list-item-title>
      <v-list-item-subtitle :class="{ 'post-subtitle-hidden': currentPostId === post.id }">
         Subtitle
      </v-list-item-subtitle>
   </v-list-item-content>
</v-list-item>

CSS:

.activeListItem {
   background-color: #c4e0ff !important;
}
.full-text {
   white-space: normal;
}
.post-subtitle-hidden {
   display: none;
}
.v-list-item__subtitle, .v-list-item__title {
   -webkit-box-flex: 1;
   -ms-flex: 1 1 100%;
   flex: 1 1 100%;
   overflow: hidden;
   text-overflow: ellipsis;
   white-space: nowrap;
}

Answer №1

To achieve a sliding effect instead of using display: none, utilize max-height: 0. Then, on the active class, set the max-height to something like 100px (an estimation of the maximum height it will reach). Lastly, apply a transition specifically on max-height.

This method will create a smooth sliding animation.

--- edit --- snippet for what is discussed in the comments

$('.title').click(function() {
    $('.subtitle').toggleClass("subtitle-show");
});
.subtitle {
  max-height: 0;
  overflow: hidden;
  transition: max-height .3s;
}

.subtitle-show {
  max-height: 100px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="wrapper">
<div class="title">
  Title
</div>
  <div class="subtitle">
      The subtitle
  </div>
</div>

Clicking on the title reveals/hides the subtitle. One drawback of this approach is a slight delay when closing the subtitle due to transitioning from a max-height of 100px to 0.

As far as current knowledge goes, there isn't a more efficient CSS solution for this issue.

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

Picture emerges from the lineup

My dilemma involves repositioning an image within a row > col-md-6. To address this, I devised two classes - .pos1 and .pos2 .pos1 { position: relative; } .pos2 { position: absolute; right: 0px; } However, when applying these classes, the ...

How to Align Title in the Center of a Section Containing Multiple Images?

I have a situation where I am using a StyledHead section to display 10 images from an API. The images are wrapped in another section called StyledHeader, which also contains an h1 element. How can I center the h1 element both vertically and horizontally so ...

Tips on implementing a Javascript function triggered by a user's click within the video player frame

<script> function greet() { alert("hello"); } </script> <iframe width="100%" height="315" src="https://www.youtube.com/embed/AGM0ibP1MRc" onclick="greet()"></iframe> .Kindly assist me, please. ...

Records were successfully updated and a confirmation message was received, however the changes did not reflect in the database

I am working on creating an "edit_post" page for my website to allow users to edit their previously posted content. Although I receive a notification saying "Updated data successfully," the changes are not being reflected in the MySQL database. <?php ...

Choose the heading element based on its class

I am trying to target a specific element by its class and store it in a variable, but I specifically need this element to be a heading element. To clarify: at any given time, there are always exactly 3 elements with this particular class on my page: an < ...

various stunning galleries accessible from a single page of thumbnail images

I'm trying to create a unique gallery experience on my website. I have a set of 6 images, each featuring a different house. What I want is for each image, when clicked, to open up a fancybox gallery showcasing 4 more detailed photos of the same house. ...

The Reason Behind Angular Error when Using CSS Custom Tags

I have the following SCSS code: main{ width: 100%; height: 840px; /*background: red;*/ margin: 10px auto; position: relative; padding: 5px 0; } section{ width: 98%; height: 600px; margin: auto; display: flex; ...

X-Ray Rendering in Three.js and Webgl

Looking to create an x-ray effect in three.js / webgl. Something like this: UPDATE I am seeking help on how to achieve a real-time render with the x-ray effect, instead of just a static image. This can be accomplished using shaders that modify density i ...

Compiling in Vue.js can be a bit sluggish

npm run dev completes the task at a rapid pace. However, when I append 1000 rows of HTML content (header) to a .vue file's template section, it takes approximately 9 minutes for compilation. The burning question: Does vue.js struggle with handling ...

Troubleshooting: Why isn't my Bootstrap glyphicon icon displaying

Has anyone encountered issues with the glyphicon icon not showing up on buttons in Safari or Chrome when using Bootstrap? I tried fixing it but couldn't. Any help would be greatly appreciated! <link href="css/bootstrap.min.css" rel="stylesheet"&g ...

What is the proper way to position elements within a <td> tag?

I am working with Products that have images of maximum size 100px. This means either the width is 100px and the height is less than 100px, or the height is 100px and the width is less than 100px. One side always measures 100px. My goal is to display the p ...

"Utilizing D3's linkHorizontal() function to dynamically update based on the

My goal is to implement a drag and drop feature with a connection line in my project. The connection line consists of a starting point ([x, y]) obtained when the mouse is clicked, and a target point ([x, y]) that tracks the mouse position as the element is ...

What is the best way to avoid adding duplicate HTML content to Bootstrap modal divs using jQuery?

In my project, I wanted to create a functionality where clicking on an image would trigger a modal box to pop up with additional content added once. However, I encountered two issues that I'm currently facing. Firstly, the header text that I intended ...

Is left padding appearing mysteriously (supernatural CSS phenomenon)?

While using the Firebug inspector tool, if you hover over #jimgMenu ul, you may notice that it has left padding without any corresponding CSS rule: Where is this mysterious left padding coming from? Why is the origin not visible? EDIT: If you navigate t ...

Switching between filters using AngularJS toggle buttons

Currently, we are in the process of converting a jQuery application into an Angular application using JavaScript. The existing jQuery app functions, but we aim to transform it into a full-fledged app utilizing the Angular framework. The main concept behin ...

Why is it necessary to separate PHP from HTML?

After exploring comments on various websites, pages, and questions I've asked about the separation of PHP and HTML, I'm curious. Does it mean structuring code like this: <?php myPhpStuff(); ?> <html> <?php morePhpStuff(); ?& ...

The onClick() function in JavaScript is encountering issues on the Firefox OS mobile application

I've been working on an app for Firefox OS mobile devices where I'm trying to trigger a Javascript function onClick() from a div attribute. It's functioning properly in regular browsers, but when I test it in the simulator, the onClick funct ...

At what point does a prop become officially designated as having the same value as what was initially passed to the component

I am experiencing unreliable behavior in my component, where a prop is passed and I need to debug it: <my-component :number="someNumber" /> The number prop is defined in my-component through a standard declaration: prop: ["number" ...

Interactive Div Updates Dropdown Selections Automatically

// function to add set of elements var ed = 1; function new_server() { ed++; var newDiv = $('#server div:first').clone(); newDiv.attr('id', ed); var delLink = '<a class="btn btn-danger" style="text-align:right;m ...

Having trouble getting XSLT to work properly with the XML file

My XSL file doesn't appear to be functioning properly with my XML data. Despite the simplicity of my code, I am unable to identify the issue. Upon linking to the XSL spreadsheet and opening the document, my XML seems to transform into plain raw Data. ...