A guide on creating a smooth CSS animation for transitioning between top and position properties

Searching for ways to enhance the visual appeal of my game's home menu page, I am currently experimenting with incorporating animated effects. Specifically, I am looking to create a dynamic entrance effect where the large multicolored title in the center descends from the top of the screen and lands in its current position, while the button and input box follow the opposite trajectory.

https://i.sstatic.net/JdkNF.png

At present, the only animation implemented is the gradient image background for the text elements.

#outer {
  text-align: center;
  position: absolute;
  ...
}

#inner {
  ...
}

@keyframes anim {
  from {
    ...
  }
  to {
    ...
  }
}
...
<h1 id='outer'>rainboz.io</h1>
<h1 id='inner'>rainboz.io</h1>

<div>
  <form align="center">
    <label id='spawnif'>this is the story of...</label>
    <label id='...

The intricate border design applied to all text components necessitates duplicate styling in the CSS code.

Answer №1

To address your query effectively, you can modify the HTML layout of your application slightly.

Create a container positioned absolutely with top and left values set to 15% and 50%, respectively. The H1 elements within this div should have position absolute (allowing them to overlap), but ensure that left and top values are not specified.

You can then animate the container by defining a new animation using @keyframes, specifying the top property of the container to transition from -30% (or any desired value) to 15%.

For a demonstration, refer to this fiddle: https://jsfiddle.net/d58t2bau/

    <div class='ctr'>
  <h1 id='outer'>rainboz.io</h1>
  <h1 id='inner'>rainboz.io</h1>
</div>


<div>
  <form align="center">
    <label id='spawnif'>this is the story of...</label>
    <label id='spawnifin'>this is the story of...</label>
    <input type='text' spellcheck='false' maxlength="20" autocomplete="off" id='nickname' placeholder="Nickname">
    <button id='playbtnot'>Play</button>
    <button id='playbtnin'>Play</button>
  </form>
</div>

CSS:

#outer {
  text-align: center;
  position: absolute;

  margin: 0;
  padding: 0;
  color: black;
  font-size: 7rem;
  font-family: coconbold;
  font-weight: 100;
  transform: translateX(-50%);
  -webkit-text-stroke: 20px black;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

#inner {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  text-align: center;
  position: absolute;

  margin: 0;
  padding: 0;
  font-family: coconbold;
  font-weight: 100;
  transform: translateX(-50%);
  font-size: 7rem;
  background: linear-gradient(45deg, rgba(255, 40, 40, 1) 15%, rgba(255, 121, 4, 1) 27%, rgba(252, 241, 73, 1) 40%, rgba(82, 252, 73, 1) 50%, rgba(73, 197, 252, 1) 60%, rgba(106, 53, 255, 1) 73%, rgba(150, 0, 214, 1) 85%);
  background-size: 200%;
  -webkit-text-fill-color: transparent;
  -webkit-background-clip: text;
  animation: anim 4s linear infinite alternate;
}

@keyframes anim {
  from {
    background-position: 0%;
  }
  to {
    background-position: 100%;
  }
}

#nickname {
  box-align: center;
  position: absolute;
  border-radius: 90px;
  top: 40%;
  left: 50%;
  margin: 0;
  padding: 3px 10px 0 9px;
  transform: translateX(-50%);
  width: 30%;
  height: 8%;
  outline: none;
  font-size: 50px;
  font-weight: 1px;
  border-color: lightgrey;
  background-color: rgb(247, 247, 247);
  border-width: 1px;
  font-family: coconbold;
  border-style: solid;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  caret-color: grey;
}

input::placeholder {
  color: transparent;
}

#spawnif {
  box-align: center;
  position: absolute;
  border-radius: 90px;
  top: 36%;
  left: 50%;
  margin: 0;
  padding: 0;
  transform: translateX(-50%);
  font-size: 20px;
  font-family: coconbold;
  color: black;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-text-stroke: 6px black;
}

#spawnifin {
  box-align: center;
  position: absolute;
  border-radius: 90px;
  top: 36%;
  left: 50%;
  margin: 0;
  padding: 0;
  transform: translateX(-50%);
  font-size: 20px;
  font-family: coconbold;
  color: rgb(245, 244, 244);
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

#playbtnin {
  box-align: center;
  position: absolute;
  border-radius: 90px;
  width: 215px;
  height: 50px;
  top: 50%;
  left: 50%;
  margin: 0;
  padding: 0;
  transform: translateX(-50%);
  font-size: 35px;
  font-family: coconbold;
  color: white;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  background-color: transparent;
  border-color: transparent;
  border-style: solid;
  border-width: 3px;
  outline: none;
}

#playbtnot {
  box-align: center;
  position: absolute;
  border-radius: 90px;
  width: 215px;
  height: 50px;
  top: 50%;
  left: 50%;
  margin: 0;
  padding: 0;
  transform: translateX(-50%);
  font-size: 35px;
  font-family: coconbold;
  color: white;
  background-color: rgb(180, 179, 255);
  border-color: rgb(110, 107, 255);
  background-size: 500px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  border-style: solid;
  border-width: 3px;
  outline: none;
  -webkit-text-stroke: 6px black;
}

#playbtn:hover {
  background-color: rgb(161, 171, 255);
  border-color: rgb(103, 101, 255);
}

.ctr {
  position: absolute;
  top: 15%;
  left: 50%;
  animation-name: float-in;
  animation-duration: 2s;
}

@keyframes float-in {
  from {
    top: -50%;
  }
  to {
    top: 15%;
  }
}

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

Verifying whether the file is an HTML image file type

My goal is to have a file input field where users can only select images. If an image is selected, the form should submit successfully, but if any other type of file is chosen, I want to display an error message. Here's what I have so far: $(document ...

Guide on how to set a custom image as the cursor when clicking on an image through javascript

Does anyone know how to use javascript to change the cursor to a custom image by updating the cursor property of the entire page? I'm getting an error in the Chrome console that says: projetFinalPage1.html:626 Uncaught TypeError: Cannot read property ...

Trouble encountered when attempting to programmatically dismiss a modal following a confirmation alert

When the user clicks on the close button, I want to display a confirmation alert to confirm if they really want to close the modal. However, I have encountered an issue with hiding the modal and preventing it from being hidden in the two solutions that I h ...

Uncovering the jsPlumb link between a pair of identifiers

Could someone help me understand how to disconnect two HTML elements that are connected? I have the IDs of both elements, but I'm not sure how to locate their connection in the jsPlumb instance. Any tips on finding the connection between two IDs? ...

Ensure that columns are neatly arranged horizontally when they do not all fit in one row

I currently have a row with 6 columns, but when they can't fit next to each other on the screen, 2 of them get pushed below, resulting in a messy layout. I could use a media query to solve this issue, however, I am curious if there is a better way to ...

Acquire PHP Data in Angular Unhandled Exception

I've encountered an error message that doesn't make any sense to me. I'm still learning Angular, so it's possible that this error is very basic, but I'm unable to resolve it. The error I'm seeing indicates a Syntax Error: Sy ...

What is the best way to position an element on the left side of the navbar without having it animated?

Could someone assist me in placing the Life's Good logo on the left side of the nav bar without applying the animation from the "btn" class? Below is a snippet of my code with an example where I want the logo highlighted in Yellow: * { padding:0; m ...

Tips on showing a success notification following form submission in HTML

I have crafted this code utilizing a combination of bootstrap, python, and html. I have omitted the css portion for brevity, but I can certainly provide it if necessary. My aim is to be able to send an email using smtplib and flask, with the added function ...

Implement a transition effect for when elements change size using the `.resizable().css` method

I attempted to incorporate a deceleration effect when resizing an element back to its original size using the resizable method. The slowdown effect should only trigger during the click event (when the "Click-me" button is pressed), not while manipulating ...

Keep the lock engaged during data input to prevent accidental slashes

Incorporating Symfony2.3.4, PHP5.6.3, Twig, HTML5, jQuery2.2.3, and CSS3. I am looking to implement a feature where the slashes (or separators in general) in an input field remain locked as the user enters numbers corresponding to the day, month, and year ...

How to Link Django URL to an HTML Button

I have the following URL defined in my urls.py file: url(r'^inline-formset/$', 'order.views.addrow', {'form_class': OrderedItemForm}, name='addrow'), Now, I want to link to this URL from a form button, but I am str ...

GZIP compression causes a total page layout malfunction

Thank you for taking the time to visit. I've been attempting to tackle this issue on my own, but it seems to be a bit overwhelming for me once again. THE SCENARIO... I have my website live on a shared hosting platform. As I delved into compressing my ...

Creating a responsive CSS image overlay using bootstrap

I am struggling with making the height of an image overlay responsive while maintaining the aspect ratio. I have tried defining it in pixels, but it doesn't work as intended. Here is the snippet of my HTML code: <ul class="img-list"> <li& ...

CSS Drop-Down Menu Fails to Function Properly in Firefox and Internet Explorer

Can you help me with this issue I'm having with my website design? In Google Chrome, Opera, and Safari, everything looks great. But in Firefox and the latest version of IE, it's a different story. Here is the HTML code: <div id="navbar"> ...

Troubleshooting HTML/CSS and JavaScript Issues with Dropdown Menus

I'm having trouble getting my dropdown menu to work properly and I can't figure out why. The JavaScript code should toggle a class that hides the language options and slides up the other tabs like "Contact". However, when I click the button, noth ...

Adjust the background color of the default Angular material theme

I'm currently working with the pre-made purple-green angular material theme using .css. I want to switch to a white background, but I'm having trouble changing it from dark grey. I've attempted removing the class "mat-app-background" from th ...

Is it necessary to include extra spaces following the input?

My HTML code looks like this: <label> <input type="checkbox"> Print document </label> One issue I am facing is that the "Print document" text is always stuck to the checkbox. I am unable to add "Print Document" in a new element or contr ...

What is the method to alter text color within a navigation bar?

I used one of the recommended bootstrap 4 navbar styles in my project, but encountered an issue when changing the background color from dark to white. This change made the text inside the navbar invisible. Despite trying various methods to change the text ...

Is there a way to determine if jQuery Mobile has already been loaded?

I am dynamically loading jqm and I'm trying to determine if it has been previously loaded in certain scenarios. Is there a method to check for the presence of jqm? ...

Tips for adjusting the color of a linear gradient in a shimmer effect

I have a puzzling question that I just can't seem to solve. My goal is to display a shimmer effect on cards as a temporary placeholder until the actual content loads. I found some CSS code in this answer, but when I tried it with a dark background, t ...