Put a hold on non-animatable CSS attributes

I am facing an issue with an animation that extends beyond the body, while the situations before and after the animation may or may not do so. I considered applying overflow:hidden; to the body element (which is set to match the viewport height), but if the content does overflow the body, I want a scrollbar to appear at the end of the animation.

My proposed solution was to use transition:overflow 0s ease 0.5s in order to delay the overflow property, hiding everything during the animation and then setting it to initial or visible once the animation has finished, allowing the scrollbar to appear only when necessary. However, this approach does not work because overflow is not an animatable property. So my question is, can non-animatable properties be delayed using pure CSS?

Answer №1

Simply put, achieving this solely with html/css is not possible. However, there is a workaround that can somewhat replicate the effect.

You could utilize the max-height property to mimic a similar outcome, although it might seem unconventional as you would have to set the max-height to a value large enough to accommodate all text.

.test {
  max-height: 50px;
  width: 150px;
  background: tomato;
  overflow: hidden;
  transition: all 0.8s, max-height 3s 5s;
}
.test:hover {
  background: blue;
  max-height: 500px;
}
<div class="test">I am only a set width. Hover me to see some magic! I am only a set width. Hover me to see some magic! I am only a set width. Hover me to see some magic!</div>


If feasible, an alternative approach would involve using a simple script. For instance, utilizing the setTimeout method:

$(document).ready(function() {
  $('.test').hover(function() {
    setTimeout(function() {
      $('.test').addClass("hovered");
    }, 3000);
  });
});
.test {
  height: 50px;
  width: 150px;
  background: tomato;
  overflow: hidden;
  transition: all 0.8s;
}
.test:hover {
  background: blue;
}
.hovered {
  overflow: visible;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="test">I am only a set width. Hover me to see some magic! I am only a set width. Hover me to see some magic!</div>

Answer №2

One effective approach is to initially set the opacity to 0 and then use a hover effect to transition it to 1, creating the desired outcome.

Answer №3

I encountered a similar issue:

.example {
 transition: all 1s ease;
 overflow:hidden;
 max-height: 0;
}
.example.withAnimation {
 max-height: 300px;
}
.example.withAnimation:after {
 overflow:inherit;
}

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

Learn a valuable trick to activate CSS animation using a button - simply click on the button and watch the animation start over each time

I already know how to do this once. However, I would like the animation to restart or begin again when the user clicks on it a second time. Here is what I have: function animation() { document.getElementById('ExampleButton').className = &apo ...

What's the best way to trigger an alert popup after calling another function?

Here are some HTML codes I've been working with: <button id="hide" onclick="hide()">Hide</button> <p id="pb">This paragraph has minimal content.</p> My goal is to have the paragraph hide first when the button is clicked, foll ...

The alert box fails to display in the correct orientation when the condition is activated

Currently, I am working on implementing a sign-up feature using PHP. My main goal is to successfully store the user-entered data in MySQL database while ensuring that no duplicate usernames are allowed during account creation. Although everything is functi ...

Error in scrolling previews detected in Jssor horizontal template maker

I've been working with Jssor Slider Maker and I'm using the vertical preview template that features two columns on the left side and a maximized image on the right side. After pulling the code from the developers pack, it includes scripts, CSS an ...

Instructions for adding a Key every time a user clicks the space Key within an Input field

I built a Movie Search Page with the OMDB API. My current issue is that the API returns an error when searching for a movie with more than one word because the API URL requires a + key between each word. I am looking for a way to automatically add the + ke ...

Is there a way for me to obtain latitude at the upper boundary of mapbox?

provides latitude and longitude based on mouse position, but I am looking for a way to retrieve the coordinates at the northernmost point of the map relative to its center. Is there a built-in method that allows me to access this information? ...

Vertical spacing on elements utilizing a position of absolute

Looking to create vertical space for elements with position:absolute and changing heights using just CSS. Any clever techniques involving containers or display properties that could be helpful? ...

Utilizing Media Queries with Dynamic Vue Properties

On one of my website pages, I always have a Div element with a Background Image that changes based on Media Queries (for example, I fetch a smaller resolution from my CDN on mobile phones). However, since I retrieve the Image URL on Page Load, I need to s ...

How can you ensure that an element returns to its original position after being animated in jQuery?

I want to add some animations to my website using jQuery, but I lack the skills to create them from scratch. I have managed to copy some code snippets, but I am facing an issue with one of my animations. When I click a button, the block animates, but I wan ...

Combine and store downloaded stylesheets in the browser into a single file

My task involves transforming a website page along with all its external stylesheets into a single HTML file with inline CSS. This is not for usage in emails, but rather to incorporate styled sections of that page into another website's page. After so ...

Is there a way to pass a variable from a Django view to an HTML page using Ajax when the user presses a key

I am developing an application that delivers real-time data to users in HTML, and I aim to dynamically update the paragraph tag every time a user releases a key. Here is a snippet of my HTML: <form method="POST"> {% csrf_token %} <p id="amount_w ...

Implementing the rotation of an element using 'Transform: rotate' upon loading a webpage with the help of Jquery, Javascript, and

A div element designed to showcase a speedometer; <div class="outer"> <div class="needle" ></div> </div> The speedometer animates smoothly on hover; .outer:hover .needle { transform: rotate(313deg); transform-origin: ce ...

What is the best way to align dynamically generated divs seamlessly together?

After creating a function that generates a grid of divs placed in a container div upon document load or user reset, I noticed a gap between each row of divs. I aim for a flawless grid where each square aligns perfectly with the next. Despite trying vario ...

Optimizing Rendering Performance: Comparing the Impact of Multiple Stylesheets vs. Single Dynamic CSS on Dynamic CSS

Currently, I am in the process of developing a website that supports "plugins" as external "displays". These plugins consist of custom full-screen HTML content managed by a client-provided JavaScript driver. The website engine utilizes an API to allow thes ...

My a:hover isn't functioning properly and my <a> tag is not redirecting to the link when clicked. Can anyone help me troubleshoot these issues?

I've created a website with multiple stacked sections. Each section is contained within a div with the class class="concertDiv". In one of these sections, I want to display an album cover on the left side and three clickable text rows on the right sid ...

Function cannot be triggered by pressing the ENTER key

I'm struggling to pass values to my function and make it run when I press the ENTER KEY in PHP The function I'm dealing with is called update() Below is the PHP code snippet: echo '<input type="text" size="23" id= n'.$row["Cont ...

Background image for input button in Internet Explorer 6

Can you create a custom background image for the input type="button" in Internet Explorer 6? ...

Tips for customizing the appearance of the active item in the navigation bar

Currently, I am developing a project with React.js using HTML, CSS, and JavaScript. My goal is to enhance the visual appeal of the active navigation item in the navbar by adding a white border around it. This way, the border will remain visible while the c ...

Tips on how to properly format a DateTime String

I need help with formatting a DateTime string retrieved from an API where it is in the format of YYYY-MM-DDTHH:MM:SS +08:00 and I want to change it to DD-MM-YY HH:MM getDataFromApi(res) { this.timestamp = this.timestamp.items[0].timestamp; console ...

what is the best way to change background image in media query for various screen sizes?

I have a customized email template with a background image. The size of the image is 600px (width), and I have applied a class called back-img for styling purposes. I am looking to override this class specifically for all mobile screen sizes, including lan ...