Comparing Animation Width with Background Image Size

I'm currently facing a challenge with making my animation resize automatically based on screen size, just like my background image does. The width of the animation seems to be inconsistent or doesn't stretch across the entire screen as I intended.

body {
  height: 100%;
  margin: 0;
  padding: 0;
  background:url(../img/Ex.jpg) no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  padding-top: 3rem;
  outline-style: solid;
  outline-color: #ffcd11;
  outline-width: thick;
  background-color: #ffcd11;
}

.rain {
  height: 100%;
  margin: 0;
  padding: 0;
  background:url(../img/snowfall2.png) center center 
  fixed,url(../img/snowfall3.png) center center fixed;
  animation: rain 1s linear infinite;
}

.rain:before {
  content: '';
  position: absolute;
  height: 100%;
  background: white;
  animation: lighting 4s linear infinite;
  opacity: 0;
}

@keyframes lighting {
0%
{
opacity: 0;
}
10%
{
opacity: 0; position: 0% 0%;
}
11%
{
opacity: 1; position: 20% 100%;
}
14%
{
opacity: 0;
}
20%
{
opacity: 0;
}
21%
{
opacity: 1;
}
24%
{
opacity: 0;
}
104%
{
opacity: 0;
}
}

@keyframes rain {
0%
{
background-position: 0% 0%;
}

100%
{
background-position: 20% 100%;
}
 }
 <div class="carousel-caption rain">
       <!-- <h1>Machine Parts Intelligence</h1> -->
        <h1 class="lead">THE NEW MACHINE MODEL INFORMATION EXPERIENCE</h1>
      </div>

I have implemented keyframes for the animation. Although I'm still working on perfecting the lighting effect, my main focus now is to ensure that the rain/snowfall effect matches the width of the background image effortlessly.

Answer №1

I just realized that by incorporating the following code into my CSS file, I was able to achieve the desired result:

.rain {
height: 100%;
margin: 0;
padding: 0;
left: 0;
right: 0;
background:url(../img/snowfall2.png) center center fixed,url(../img/snowfall3.png) 
center center fixed;
animation: rain 1s linear infinite;
}

Implementing a left and right function effectively resolved the issue and also enlarged the width of my website.

Answer №2

Without the actual images or a visual representation of your intention, it's challenging to grasp the exact goal you were aiming for. However, based on my interpretation, I have made some adjustments to hopefully match what you had in mind.

The key change I implemented was modifying the background-position property in your keyframe so that the image is centered within the element with a value of 50%. Given the name "rain," I also adjusted it to simulate a downward falling effect.

body {
  height: 100%;
  margin: 0;
  padding: 0;
  background:url('https://images-na.ssl-images-amazon.com/images/I/51IwmuOPQyL._SL1052_.jpg') no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  padding-top: 3rem;
  outline-style: solid;
  outline-color: #ffcd11;
  outline-width: thick;
  background-color: #ffcd11;
}

.rain {
  height: 100%;
  margin: 0;
  padding: 0;
  background:url('https://www.ikea.com/gb/en/images/products/euphorbia-acrurensis-potted-plant__0654026_pe708251_s5.jpg') center center 
  fixed, url('https://media.istockphoto.com/photos/cactus-in-pot-picture-id486466536?k=6&m=486466536&s=612x612&w=0&h=3CJO4XNOcS3WtAdMU4A9TuCbcwxnE9Rr6lHU4GDSwhE=') center center fixed;
  animation: rain 1s linear infinite;
}

.rain:before {
  content: '';
  position: absolute;
  height: 100%;
  background: white;
  animation: lighting 4s linear infinite;
  opacity: 0;
}

@keyframes lighting {
0%
{
opacity: 0;
}
10%
{
opacity: 0; position: 0% 0%;
}
11%
{
opacity: 1; position: 20% 100%;
}
14%
{
opacity: 0;
}
20%
{
opacity: 0;
}
21%
{
opacity: 1;
}
24%
{
opacity: 0;
}
104%
{
opacity: 0;
}
}

@keyframes rain {
0%
{
background-position: 50% 100%;
}

100%
{
background-position: 50% 0%;
}
 }
<div class="carousel-caption rain">
       <!-- <h1>Machine Parts Intelligence</h1> -->
        <h1 class="lead">THE NEW MACHINE MODEL INFORMATION EXPERIENCE</h1>
      </div>

If this doesn't align with your vision, please let me know, and I can make further adjustments.

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

Maintaining Aspect Ratio and Adding Letterboxes with Next.js Image

In my Next.js app, there is a section dedicated to displaying selected photos from a gallery. It's crucial for this area to maintain a fixed size of 566px*425px as users navigate through images or when a photo is loading. While the layout is responsiv ...

Visual Composer now appends "?id=" to the background images of columns and rows, enhancing the customization

I am in the process of improving the performance of a WordPress site that is using the Visual Composer plugin. When checking GTmetrix results, I came across this issue: Ensure resources are served from a consistent URL https://example.com/wp-content/uploa ...

Is it possible to show the Display Center within the dropdown menu?

Hello everyone, this is my first time posting on stackoverflow. I have a question about centering the select options. Could someone please take a look at the image attached and let me know if it's possible? <select multiple="multiple" nam ...

Executing VueJS keyup handler after the previous onclick handler has been executed

Link to example code demonstrating the issue https://codepen.io/user123/pen/example-demo I am currently facing an issue with a text field named search_val that has a watcher attached to it. The text field includes a v-on keyup attribute to detect when th ...

Issue with embedding icon within input field in Bootstrap version 4.1

I am currently implementing a project using Angular 6 along with the latest version of Bootstrap v4.1. I am attempting to create a reactive form with icons within input fields. As there is no direct way in bootstrap to place icons on the left side of input ...

The left and right edges are not extending across the entire screen

Can anyone help me determine if this is a duplicate issue? I'm unsure why my left and right borders are not extending the full width of the screen. The website in question is ojs.monojitbanerjee.co.cc Here is the structure: <body> <div id= ...

How can I retrieve the current background color and revert it back after a .hover event?

I am trying to use the .hover function to change the background color of a menu. Each menu item has a different background color, so I want it to return to its original color when the user hovers off. In other words, I want the script to read the current b ...

What is the best way to align a search box within a Bootstrap navbar?

Seeking assistance to center the search box within my Bootstrap navbar without disrupting alignment. I am aiming for a similar look as seen on linkedin.com. Any suggestions on how to achieve this? Here is a JSFiddle link to my navbar: https://jsfiddle.ne ...

Turning off FavIcon.ico Can Enhance Performance

element: Currently, I have two websites being hosted on AEM or cq5 with distinct domains. Both websites share the same favicon on the new domain. I have attempted to remove this in the head.jsp template, but the favicon continues to display. Despite remo ...

Using Angular's [ngIf], [ngIfElse], and [ngIfElseIf] functionalities enables dynamic content rendering

Currently, I have the following code snippet: <ng-container *ngIf="someCondition"> <ng-template [ngIf]="cd.typedType === 'first'" [ngIfElse]="Second"> <div class="row"> fir ...

Can you explain the distinction between using a period in a class selector and not using one?

Could someone please clarify the meaning of the code snippet below? <div class="cls1 cls2">abcd <div class="cls2"> adfffff </div> </div> .cls1 { background-color: yellow; } /*sample1 .cls1.cls2 { color: red; } */ /* ...

Looking to position the Secondary Navigation Bar on squarespace at the bottom of the page, distinct from the primary Navigation Bar

When SALES PAGE becomes the secondary navigation option Instructions for positioning style to Bottom Center I am attempting to place it at the bottom of the navigation bar. Can you provide me with the necessary code or styles in squarespace? When I choose ...

contrasting ionic and android software development kits

I am interested in developing an android application and have some knowledge about Ionic, which is also used for creating mobile apps. I have more experience with Android development and am curious to understand the distinctions between the two platforms ...

``There seems to be an issue with implementing the SlideDown feature in JavaScript

I am having an issue with a code where the expected behavior is to slide down a div when a person hovers over text, but it's not working. Can someone please review and identify the cause of this problem? <script type="text/javascript" src="/js/jqu ...

Get the value of an HTML element

Is there a way to retrieve the value of an HTML element using PHP or JavaScript, especially when the value is dynamically loaded from another source? I have tried using jQuery with the DOM ready event, but often encounter the issue where the element's ...

After sending a post request, the form in HTML with Node.js is returning an undefined response

Upon creating an HTML <form></form> object to capture a username, email, and password, I encountered an issue where the value returned is always undefined when accessing req.body.name or any other field. It seems like the form is not functionin ...

When hovering over nav bar links, shadows are not displayed

When hovering over the navbar links, I am able to change their color but a shadow at the bottom is missing. Is there a way to add a shadow at the bottom like it had before when not hovered? Visit this link for more information ...

Parent div is positioned absolutely with overflow set to hidden

I am facing a unique requirement where the parent div has an absolute position and the child div also has an absolute position. Inside the parent div, I have set overflow: hidden to hide the extra width of the child div. However, this setup is not working ...

Flexbox: Arrange header and footer in a sidebar layout using flexbox styling

In my content layout, I have structured the sections as header, content, and footer. While I want to maintain this order for small devices, I am looking to shift the header and footer to the sidebar on desktop. I have already implemented this using floats ...

Using jQuery to set menu active states for a sprite-based navigation with distinct class names

I'm curious about how to accomplish this using JQuery. I have a menu where each item must have a unique class name in order for the CSS to properly display a sprite background position shared by all items. When an item is clicked, I also need to activ ...