Continuous CSS animations with enduring final state

I have a div element serving as the main container for my webpage. Inside this, there is another div element which functions as a curtain - when activated, it covers the entire page with a dark semi-transparent layer similar to a lightbox. This deactivates the page and allows for the display of warning dialogs or picture boxes on top.

I can easily accomplish this effect and functionality using JavaScript. However, I am curious to know if it could be achieved solely through CSS animations?

<div id='globalCon'>
    <div id='curtain' class='enabled'></div>
    <div id='contentA'></div>
    <div id='contentB'></div>
    ... 
</div>

When the curtain is not active, it should have an opacity of 0 and ideally be set to display:none; to keep it hidden. Upon activation, it should change to display:block and animate the opacity to 0.8. Upon deactivation, the opacity should animate back to 0, and then it should revert to display:none;

While I can achieve this easily with JavaScript, I am interested in exploring whether and how it can be done using only CSS.

Answer №1

Here is an example of how to use the CSS property: animation-fill-mode: none/backwards/forwards/both;

The ‘animation-fill-mode’ attribute determines which styles are applied during and after the execution of the animation

For more information, refer to the official specification.

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

Display when moving up and conceal when moving down

Is there a way to make the div appear when scrolling up and down on the page? I'm new to jquery and could use some assistance, please. ...

Create a CSS menu that centers the links

Here is the CSS code I am using for my horizontal menu: nav { height: 40px; width: 100%; background: #F00; font-size: 11pt; font-family: Arial; font-weight: bold; position: relative; border-bottom: 2px solid # ...

Is there a way to generate a perfectly proportioned rectangular treemap using d3.js?

When attempting to generate a rectangular treemap in d3.js, I encountered an issue where the resulting shape was not as desired. There were instances of missing data and empty spaces within the rectangular treemap. Upon investigation, I found that removin ...

When the webpage is reduced in size, there is an abundance of unused white space

As I resize my website to 768 pixels, I notice an excess of white space on the left side. I've tried removing default padding and margins, adjusting image sizes, but the issue persists. Here is a snippet of the code. Any assistance would be greatly ap ...

Having difficulty adjusting the color of the navbar in Bootstrap 4

I recently designed two navigation bars using bootstrap, but encountered an issue when attempting to change the background color of the second navigation bar. Despite following a tutorial video closely, the color did not update as expected. The main css fi ...

What is the best way to eliminate the space between the website's border and the image?

Is there a way to eliminate the space between the left and right borders? I want the picture to fill 100% of the browser window. https://i.stack.imgur.com/gqgOs.png img.test { display: block; outline: 0px; padding: 0px; margin: 0px; } <img c ...

What is preventing the inner box from stretching to match the width of the outer box?

This question isn't really related to academics, it's more of a work-related inquiry that I've simplified into a basic question. I placed one div inside another expecting the inner div to inherit the width of the outer div. Initially, this ...

Add-on Group for Form Inputs - Is a style element missing? (Bootstrap 4)

I am looking for a way to incorporate a Bootstrap4 input group label between two input fields. While there are "prepend" and "append" styles available, in this scenario, I require a "center" style which seems to be missing. Does anyone have a solution for ...

Issue with Bootstrap table cell not following specified widths

I have implemented a vue app using regular Bootstrap 4 without Vue-Bootstrap. The issue I'm facing is with one of the responsive-tables on my site. Despite trying different methods, including copying a fully functional table, this specific table does ...

Implementing the Upload Feature using AngularJS

Currently, I'm facing a challenge in implementing an upload button on my webpage using AngularJS and Bootstrap. Specifically, I am having trouble assigning the (upload) function to that button in AngularJS. The goal is for the button to enable users t ...

Stop the sudden jump when following a hashed link using jQuery

Below is the code snippet I am working with: $( document ).ready(function() { $( '.prevent-default' ).click(function( event ) { event.preventDefault(); }); }); To prevent the window from jumping when a hashed anchor ...

Video Background, Adjusting Scale to Fit Height and Cropping Width as Necessary

Forgive me if this question has already been posed, but my search through various related discussions has not yielded the exact solution I'm looking for. My dilemma involves a 1280x720 video that I want to use as the background on my webpage. I need ...

Variable in SCSS not being applied as expected

I'm currently grappling with understanding why my alterations to the system colors aren't reflecting as expected. When viewing in Chrome, this is the image I see. https://i.sstatic.net/H6YbW.png However, this is what I anticipate should be vis ...

What is the best way to deactivate the button when there are no arrays present in the input?

In my HTML, the input value is populated by user selection and stored in array format (e.g. 45[45, 6, 33], 67[67,2,5] and so on..). Essentially, the value will look like this: <input id="question_string" type="hidden" value="{}"> <input class="su ...

Ways to display success message following JavaScript validation

I've been working on creating a form that displays a success message after JavaScript validation checks are successful. To show the success message, I'm utilizing Bootstrap alert. I split my code into two files - one for common validation functio ...

Weather Application featuring Circular Slider

I've been on the hunt for a circular slider animation. Imagine it working like this: <input type="range" min="0" max="50" value="0" step="5" onchange="showValue(this.value)" /> <span id="range">0</span> function showValue(newValue ...

How can you align square cells within a container using CSS grids while maintaining a consistent grid gap?

Our objective is to perfectly align square cells with the edges of their container while maintaining a consistent gap between cells in each row and column. Although this Codepen solution is close, there are two key issues: (1) vertical spacing doesn' ...

Assistance in configuring Zurb Foundation 5 for optimal integration with Laravel

As a relatively new user to Laravel with previous experience using older versions of Foundation, I am currently in the process of setting up a new Laravel project. My goal is to integrate the Foundation framework into my project, but I find myself a bit co ...

Center a span vertically inside a div as the text within the span grows to occupy the entire div

I am facing an issue with a table that has 25 td's. Each td contains specific elements as shown below: <td> <div> <span> text </span> </div> </td> Additionally, there is a script in place that adj ...

JavaScript Refresh Function Malfunctioning

Currently, I have a JavaScript code snippet on my website that automatically refreshes an iframe every three seconds. window.setInterval(function() { reloadIFrame() }, 3000); function reloadIFrame() { var frame = document.getElementById("if ...