Tips on achieving vertical movement within a div element from the bottom of the wrapper to the

I am struggling to animate a .alert div within its wrapper to fly up from the bottom of the wrapper by 40px. However, I am encountering difficulty as the alert div does not start at the bottom of the wrapper as intended. The desired behavior is for it to start at the bottom line, move up by 40px, and then stop. Currently, it starts at the top of the wrapper and moves out of it.

.wrapper {
width: 500px;
height: 300px;
border: 1px solid #333;
}
.alert {
  width: 360px;
  height: 40px;
  background: red;
  position: relative;
  animation: flyup 2s;
  animation-fill-mode: forwards;
  bottom: 0px;
}

@keyframes flyup {
  0%   {background: green; left: 0px; bottom: 0px;}
  100% {background: green; left: 0px; bottom: 40px;}
}
<div class="wrapper">
    <div class="alert">This content should fly up 40px upwards in 2 seconds</div>
</div>

Fiddle: https://jsfiddle.net/Lfz4rb5d/

Answer №1

To achieve the desired effect, you must add position: relative to the .wrapper class and position: absolute to the .alert class. This will ensure that the .alert element is positioned relative to the .wrapper element.

.wrapper {
  position: relative;
  width: 500px;
  height: 300px;
  border: 1px solid #333;
  background: #fff;
}

.alert {
  width: 360px;
  height: 40px;
  background: red;
  position: absolute;
  animation: flyup 2s;
  animation-fill-mode: forwards;
  bottom: 0px;
}

@keyframes flyup {
  0% {
    background: green;
    left: 0px;
    bottom: 0px;
  }
  100% {
    background: green;
    left: 0px;
    bottom: 40px;
  }
}
<div class="wrapper">
  <div class="alert">This content should fly up 40px to the top in 2 seconds</div>
</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

Accordion menu with smooth CSS3 transitions

I created a unique accordion menu to replace the select form control, and I am interested in using CSS3 transitions to give it a smooth expand and contract effect. Feel free to check out my work on jsfiddle: http://jsfiddle.net/hKsCD/4/ In order to achi ...

Issue encountered while trying to display images next to each other using only HTML and CSS

https://i.sstatic.net/OAjCG.jpg I am facing an issue with the vertical space between the top and bottom rows of my portfolio. There seems to be some unwanted space in the rows that I cannot account for. It doesn't seem to be a margin or padding withi ...

Challenges with the efficiency of hover effects

I have a div with a background image and inside that div, there is a component called Hero. I want to add a simple hover effect on a div with a className newBigButton. However, the transition is laggy when the background image is present. Here's the c ...

What could be causing the padding of my anchor element to extend outside the boundaries of its parent list

In the provided images, it is evident that the <li> element is failing to expand and is disregarding the padding of the parent element.</p> <p><a href="https://i.stack.imgur.com/4ZH65.png" rel="nofollow noreferrer"></a></p& ...

It is not possible to place the cursor before a non-contenteditable div within a contenteditable div

Here is the layout I am working with: <div contenteditable=true> /// <div contenteditable=false>not editable</div> /// </div> One problem I'm facing is that when the non-contenteditable div is the first element on a ...

Do you think there is a more optimal method for achieving this?

Here is the core concept: I developed it in a fluid manner like this: Do you have any suggestions for improving the way I implemented this? ...

How to customize TextField error color in Material-UI using conditional logic in React

Currently, I am incorporating the React Material-UI library into my project and faced with a challenge of conditionally changing the error color of a TextField. My goal is to alter the color of the helper text, border, text, and required marker to yellow ...

Differences between using CSS properties and AngularJS filters:CSS properties

When working on an angularjs application, one task may be to convert a string to uppercase. There are 2 options available to achieve this, both yielding the same result. However, it is important to consider the scenarios in which one option may be preferre ...

"Maximizing Bootstrap Grid System in Bootstrap Modals: A Step-by-Step Guide

I am currently working with Bootstrap 5 modal. I am attempting to implement the Bootstrap grid system inside the modal, however, I am experiencing unwanted margins between the modal body and the grids. How can I remove these margins? Any assistance on t ...

Unable to align only one link on the right as flex-end is not functioning correctly

I need help rearranging my row of items displayed at the top of the page. I want one item to appear on the far right while the rest are aligned to the left. I attempted using align-self: flex-end but it didn't work. Here's the current code snippe ...

Display a single image on the tablet and a distinct image on the computer

Currently, I am encountering an issue with my webpage located at . The problem lies in the right upper corner where a ribbon is located. However, when viewing the page on a tablet, the ribbon overlaps with my menu. To resolve this, I thought about displa ...

What causes the inability to separate the span size from the parent div when enlarging the span width?

Check out this Relevant Fiddle: https://jsfiddle.net/promexj1/1/ I'm working on adjusting the widths of two child spans within a parent div to be slightly smaller than the parent itself (due to starting translation 10px to the right for one of the sp ...

The bottom row of elements is aligned to the left in a grid that is centered

Within a div with text-align:center, I have multiple same-size blocks set to display:inline-block. | _____ _____ _____ _____ | | | | | | | | | | | | | 1 | | 2 | | 3 | | 4 | | | |_____ ...

Is there a way to implement the border-box property for Internet Explorer versions 6 and

Similar Question: How to implement box-sizing in IE7 Anyone know a method or workaround to apply box-sizing:border-box; in IE6 and IE7? Even just for IE7? ...

Rendering High-quality Images in Internet Explorer Browser

Currently, I am working on optimizing my website for high resolution monitors, particularly the new iPad. The site is already formatted to my liking, with images having increased resolutions while still fitting into specific DIVs. For instance, an image wi ...

Minimize the entire project by compressing the .css, .js, and .html files

After recently incorporating Grunt into my workflow, I was thrilled with how it streamlined the process of minifying/concatenating .css files and minifying/uglify/concatenating .js files. With Grunt watch and express, I was able to automate compiling and ...

Animating an image into a Vue.js div

Is it possible to create a dynamic image animation using Vue.js? I am looking to create an interactive "Add to Cart" experience where when a user clicks on the button, the product's image smoothly glides over to the shopping cart icon before fading a ...

Update the font style of the navigation bar

Hey there! I recently downloaded a template from this website: . However, I'm facing an issue with the nav bar displaying strange fonts when using Vietnamese letters. For example, "Nước" shows up as all uppercase and the letters "uo" are shortened. ...

The issue with border radius property on the scrollbar of a bootstrap dropdown menu

Is the scroll bar of a bootstrap dropdown menu sticking out of the box when using the border radius property? Looking for a solution? Check out this example code and preview: <div class="container py-4"> <div class="dropdo ...

Is there a way to change the text color of a table when hovering over an image using Javascript?

UPDATE: I believe I have solved the issue! However, if anyone has suggestions on a better way to achieve this, I am open to learning. I'm still fairly new to Javascript! I have an image and a table containing text. My goal is to change the color of S ...