Incorporate a background image and overlay it with CSS animations for a dynamic effect

I have set up a fiddle, but it seems like the display is not quite right. You can check it out here - http://jsfiddle.net/kVNQb/ - although it might be helpful to take a look at the code regardless.

The snow animation I am using is from this website:

My goal is to have a background image and then animate the snow on top of it. Currently, I am facing an issue where I lose either the animated snow or the background image.

Do I need to create an ID and set the desired image as a background for that?

Here is the HTML code:

<body>

    <div class="row">
        <div class="large-12 columns">
            <div id="container">
        </div>
            </div>

    </div>

</body>

CSS code:

/*Custom CSS styles used in addition to the standard Foundation 4 style sheet*/
.fixed-body {
 background-image: url(http://s17.postimg.org/9htu61zjj/background.jpg);
}


* {
    margin: 0;
    padding: 0;
}

a {
    color: white;
    font-style: italic;
}

/*Keyframes*/

@keyframes snow { 
    0% { background-position: 0px 0px, 0px 0px, 0px 0px }

    100% { background-position: 500px 1000px, 400px 400px, 300px 300px }
}

@-moz-keyframes snow { 
    0% { background-position: 0px 0px, 0px 0px, 0px 0px }

    100% { background-position: 500px 1000px, 400px 400px, 300px 300px }
}

@-webkit-keyframes snow { 
    0% { background-position: 0px 0px, 0px 0px, 0px 0px }

    50% { background-color: #b4cfe0 }

    100% {
        background-position: 500px 1000px, 400px 400px, 300px 300px;
        background-color: #6b92b9;
    }
}

@-ms-keyframes snow { 
    0% { background-position: 0px 0px, 0px 0px, 0px 0px }

    100% { background-position: 500px 1000px, 400px 400px, 300px 300px }
}

#container {
    width: 800px;
    margin: 200px auto;
    text-align: center;
    color: white;
    font: 100px/1 'Spirax', cursive;
    text-shadow: 0px 0px 4px rgba(0,0,0, 0.5);
}

#container p { font: 12px/1.5 "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif }

Answer №1

To achieve this effect, it is important to ensure that the background-color is set to transparent in both the div and the animation frames. You can see a demonstration of this on this Fiddle: http://jsfiddle.net/f92gB/

Here is the HTML structure:

<body>
    <div id="container"></div>
</body>

And here is the accompanying CSS code:

* {
    margin: 0;
    padding: 0;
}

a {
    color: white;
    font-style: italic;
}

/*Keyframes*/

@keyframes snow { 
    0% { background-position: 0px 0px, 0px 0px, 0px 0px }

    100% { background-position: 500px 1000px, 400px 400px, 300px 300px }
}

@-moz-keyframes snow { 
    0% { background-position: 0px 0px, 0px 0px, 0px 0px }

    100% { background-position: 500px 1000px, 400px 400px, 300px 300px }
}

@-webkit-keyframes snow { 
    0% { background-position: 0px 0px, 0px 0px, 0px 0px }

    50% { background-color: transparent }

    100% {
        background-position: 500px 1000px, 400px 400px, 300px 300px;
        background-color: transparent;
    }
}

@-ms-keyframes snow { 
    0% { background-position: 0px 0px, 0px 0px, 0px 0px }

    100% { background-position: 500px 1000px, 400px 400px, 300px 300px }
}

body {
    background-image: url("http://s17.postimg.org/9htu61zjj/background.jpg");
    background-size: cover;
    height: 500px;

}

#container {
    height:500px;
    margin: 0;
    text-align: center;
    color: white;
    font: 100px/1 'Spirax', cursive;
    text-shadow: 0px 0px 4px rgba(0,0,0, 0.5);
    background-color: transparent;
    background-image: url('http://img138.imageshack.us/img138/5230/snowh.png'), url('http://img594.imageshack.us/img594/9146/snow3q.png'), url('http://img196.imageshack.us/img196/5065/snow2l.png');
    -webkit-animation: snow 20s linear infinite;
    -moz-animation: snow 20s linear infinite;
    -ms-animation: snow 20s linear infinite;
    animation: snow 20s linear infinite;
}

Answer №2

If you're looking to enhance your website with a dynamic full and responsive background image, look no further than this handy jQuery plugin. Simply visit the following link for step-by-step instructions on how to implement it:

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

Utilizing CSS nth-child on dynamically generated HTML in Angular

Ensuring that the columns are floated to the left without large gaps between rows is my current challenge. Here's the HTML structure I'm working with: <div class="row hide-for-small"> <div ng-repeat="module in modules"> ...

What are some tips for designing HTML email templates?

Check out this example of an HTML email <div style="width:650px;"> <div class="begining"> <p> Dear <span>' . $name . '</span><br/>Thank you for your booking </p> & ...

Navigate to the top of the page using jQuery

Attempting to implement a simple "scroll jump to target" functionality. I've managed to set it up for all parts except the "scroll to top". The jumping works based on the tag's id, so it navigates well everywhere else, but not to the very top. He ...

What is the best way to eliminate the unwanted white space below the footer on a webpage

I'm working on a website and I've noticed that at the end of the footer, there is a large block of white space that shouldn't be there. I've tried adjusting the HTML and CSS code, but nothing seems to fix the issue. Strangely, other pag ...

The signature only appears once the modal bootstrap has been resized

After a user enters data in my application, they are required to sign using the signature-pad plugin found here: https://github.com/szimek/signature_pad. The signature is then placed in a modal created using bootstrap4. The problem arises when I try to op ...

Is there a way to overlay a div on a particular line within a p element?

Within this paragraph lies a collection of text encapsulated by a < p > tag. When this content is displayed on the page, it spans across 5 lines. My objective is to creatively style and position a < div > tag in order to highlight a specific li ...

Adjust the dimensions of the image carousel in Twitter Bootstrap

Here is the code that I am currently working with: <div class="col-sm-4"> <div class="card"> <div class="card-block"> <div class="col-sm-4"> <div id="carouselExampleIndi ...

CSS z-index property not functioning properly for Flowplayer on Firefox browser

I am attempting to create a layered div using z-index, with one of the layers containing a flowplayer. Once the layer is properly created, I plan to update the div's z-index value based on the logic of the program. The following code functions correct ...

Achieve smooth scaling of font size in CSS according to body width without the need for JavaScript

Can the font size be smoothly scaled in relation to the width of the body or parent element? I am seeking a solution that does not involve javascript. Is it feasible to relate rem to a specific width? ...

Which CSS preprocessor is the best choice for WordPress: SASS or

After comparing SASS and LESS, I found that SASS is the clear winner in my opinion. Unfortunately, setting up SASS on my server requires ruby, gems, and other tools that I don't have access to. On the other hand, it seems like adding LESS to my proj ...

Optimize Your Reactstrap Carousel Images for Responsiveness

Despite my extensive search efforts, I have found very limited documentation on how to make images within a ReactStrap carousel responsive to resizing. While the ReactStrap carousel itself is responsive, the images inside it do not resize accordingly. So ...

issues encountered when attempting to modify the background color of navigation items using bootstrap

Presently, I am focusing on enhancing the navigation bar of my website, but I have encountered an issue with my JavaScript code. I have implemented a scroll-spy feature in my navigation and added JavaScript for smooth scrolling. Additionally, I aim to make ...

Achieving priority for style.php over style.css

Having trouble with theme options overriding default CSS settings in style.css. Here's what I have in my header.php: <link rel='stylesheet' type='text/css' media='all' href="<?php bloginfo( 'stylesheet_url&apo ...

forming a boundary that stands alone, unattached to any other boundaries

I am trying to design a navigation bar that resembles the one depicted in the image provided. The concept involves creating a navigation bar where each border is separated from the others, potentially achieved using hr tags. However, I am struggling to fi ...

How can I ensure that Div and its contents are only responsive to changes in width?

Initially, I'm feeling a bit confused but I'll try my best to articulate my issue and what I need. Within a div element, there's another div that I want to move left and right only, following the same path as an image when resizing (refer t ...

When you hover over an image, its opacity will change and text will overlay

I am looking for a way to decrease the opacity and overlay text on a thumbnail image when it is hovered over. I have considered a few methods, but I am concerned that they may not be efficient or elegant. Creating a duplicated image in Photoshop with the ...

The collapsible hamburger navbar is unresponsive and fails to collapse

Currently, I am working on a project that requires my navigation bar to be scaled down to a hamburger menu for mobile view. I have managed to do most of it, but for some reason, the navigation is not collapsing within the hamburger bar. I have been tweakin ...

CSS: concealing certain portions of an element's content

I don't have control over the following markup: <p class="filename"> <img src="http://domain.com/uploads/image_gallery/_thumbs/Chrysanthemum.jpg" alt="Chrysanthemum.jpg"> <br> Chrysanthemum.jpg </p> Is it possible ...

Steps to switch the displayed ionicon when the menu is toggled

My goal is to display the 'menu-outline' ionicon on my website until it is clicked, at which point the icon will change to 'close-outline' and vice versa. I am utilizing jQuery for this functionality. Although I am aware of how to togg ...

sophisticated HTML navigation bar

I am looking for a way to create a menu where the drop-down items overlay the rest of the menu when the screen width is small. Here is my current code: nav{ line-height:100%; opacity:.9; }nav ul{ background: #999; padding: 0px; border-radius: 20px; ...