Floating Bottle on Water CSS Animation

Floating Bottle on Water CSS Animation
Code Snippet:Floating Bottle Loader
Author: CChuan
Published: January 16, 2024
Last Updated: January 22, 2024
Downloads: 4,784
License: MIT
Edit Code online: View on CodePen
Read More

This simple CSS code snippet helps you to create a floating Bottle on Water animation. It uses a bottle image and CSS wave animation to float the bottle on water with up and down transitions.

How to Create a Floating Bottle on Water Animation in CSS

1. Create the HTML structure for the image container as follows:

<div class="imgContainer"><img class="wave" src="https://i.pinimg.com/originals/64/91/54/6491542a239217a7d44bfba368cd06c8.png" alt=""/><img class="bottle" src="https://i.pinimg.com/originals/67/19/71/6719713708a3a22081b18e9a520c85e8.png" alt=""/><img class="wave delay" src="https://i.pinimg.com/originals/64/91/54/6491542a239217a7d44bfba368cd06c8.png" alt=""/><img class="wave delay" src="https://i.pinimg.com/originals/64/91/54/6491542a239217a7d44bfba368cd06c8.png" alt=""/></div>
<h1>Loading...</h1>

2. Add the following CSS styles for the bottle animation.

@import url("https://fonts.googleapis.com/css?family=Lily+Script+One&display=swap");
html, body {
  padding: 0;
  margin: 0;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  background-color: #ddd;
}

h1 {
  font-size: 2em;
  font-family: "Lily Script One";
  color: #505e77;
  letter-spacing: 7px;
}

.imgContainer {
  position: relative;
  width: 200px;
  height: 220px;
  overflow: hidden;
  margin: 10px auto;
}
.imgContainer img.bottle {
  width: 50%;
  position: absolute;
  left: 50%;
  transform: translate(-50%, 0);
  bottom: 18px;
  -webkit-animation: floating 1.75s ease-in-out infinite alternate;
          animation: floating 1.75s ease-in-out infinite alternate;
}
.imgContainer img.wave {
  -webkit-animation: wave 2.3s linear infinite;
          animation: wave 2.3s linear infinite;
  -webkit-animation-delay: -0.2s;
          animation-delay: -0.2s;
  position: absolute;
  bottom: 0;
  width: 200%;
}
.imgContainer img.wave.delay {
  -webkit-animation-duration: 3.5s;
          animation-duration: 3.5s;
}

@-webkit-keyframes wave {
  0% {
    transform: translateX(0%);
  }
  100% {
    transform: translateX(-50%);
  }
}

@keyframes wave {
  0% {
    transform: translateX(0%);
  }
  100% {
    transform: translateX(-50%);
  }
}
@-webkit-keyframes floating {
  from {
    transform: translate(-50%, 10px);
  }
  to {
    transform: translate(-50%, -10px);
  }
}
@keyframes floating {
  from {
    transform: translate(-50%, 10px);
  }
  to {
    transform: translate(-50%, -10px);
  }
}

That’s all! hopefully, you have successfully created a floating bottle on water animation using CSS. If you have any questions or suggestions, feel free to comment below.

2 thoughts on “Floating Bottle on Water CSS Animation”

    • Hi Vignesh!
      Simply copy the CSS code, open your jsp file and paste it between the <style>and </style> tag. Similarly, copy the HTML code and paste it where you want to display this animated loader.

      Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About CodeHim

Free Web Design Code & Scripts - CodeHim is one of the BEST developer websites that provide web designers and developers with a simple way to preview and download a variety of free code & scripts. All codes published on CodeHim are open source, distributed under OSD-compliant license which grants all the rights to use, study, change and share the software in modified and unmodified form. Before publishing, we test and review each code snippet to avoid errors, but we cannot warrant the full correctness of all content. All trademarks, trade names, logos, and icons are the property of their respective owners... find out more...

Please Rel0ad/PressF5 this page if you can't click the download/preview link

X