Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Waves in CSS or SVG

I'm trying to create soft waves with CSS and am having some trouble. I'm using border-radius right now to create waves but it looks more like clouds. I tried using transform: translateZ(180deg); but the div color is then upside down.

Here's what I want: Waves in CSS or SVG

Here's what I have: Waves made with CSS

.wave1 {
  left: 0%;
  margin-left: -50px;
}

.wave2 {
  margin-left: -69px;
}

.wave3 {
  margin-left: -69px;
}

.wave4 {
  margin-left: -69px;
}

.waves {
  width: 200%;
  clear: none;
  z-index: 100;
  position: absolute;
  margin-top: 200px;
  margin-left: -150px;
}

.waves div {
  float: left;
  width: 500px;
  height: 100px;
  border: solid 5px #000;
  border-color: transparent;
  border-radius: 70%/100px 100px 0 0;
  background-color: #fff;
}

.bottom-half {
  width: 100%;
  height: 50%;
  top: 70%;
  position: absolute;
  background-color: #fff;
}

.background-waves {
  width: 200%;
  clear: none;
  z-index: 50;
  position: absolute;
  margin-top: 190px;
  margin-left: 75px;
}

.bwave1 {
  left: 0%;
  margin-left: -50px;
}

.bwave2 {
  margin-left: -69px;
}

.bwave3 {
  margin-left: -69px;
}

.bwave4 {
  margin-left: -69px;
}

.background-waves div {
  float: left;
  width: 500px;
  height: 100px;
  border: solid 5px #000;
  border-color: transparent;
  border-radius: 70%/100px 100px 0 0;
  background-color: #fff;
  opacity: 0.5;
}
<div class="waves">
  <div class="wave1"></div>
  <div class="wave2"></div>
  <div class="wave3"></div>
  <div class="wave4"></div>
  <div class="wave5"></div>
</div>
<div class="background-waves">
  <div class="bwave1"></div>
  <div class="bwave2"></div>
  <div class="bwave3"></div>
  <div class="bwave4"></div>
  <div class="bwave5"></div>
</div>
like image 830
SlugCoder Avatar asked Jun 21 '17 02:06

SlugCoder


People also ask

How do I add waves to SVG?

One of the easiest ways to add waves to an element is the ShapeDriver tool. It allows you to create a wave effect generating an SVG path and required CSS code to style it. To add more complex layered waves, you can use the Haikei app to randomly generate a variety of beautiful waves, blobs, and other shapes.

How do you make a wave shape in CSS?

Let's try . 8 for example. --size: 50px; --R: calc(var(--size) * 1.28); mask: radial-gradient(var(--R) at 50% calc(1.8 * var(--size)), #000 99%, #0000 101%) calc(50% - 2*var(--size)) 0/calc(4 * var(--size)) 100%, radial-gradient(var(--R) at 50% calc(-.

How do I make a background wavy in CSS?

How to Create Wave Background using CSS ? CSS code: In this section, we will use some CSS property to design the wave background. First we will add a basic background to the section and then use the before selector to set the wave png file on top of our background.

What is Wave in HTML?

Waves are simple designs that can be generated on an HTML page which enhances the overall look of the website and make it more attractive and designer.


1 Answers

I would suggest using an inline handcoded SVG. Your shapes are pretty simple an making the waves with the SVG <path> element is easy.
All you need to know about the SVG path on MDN. In the following example, I used two path elements with quadratic bezier curves to make the waves :

svg {
  background: url('https://farm9.staticflickr.com/8461/8048823381_0fbc2d8efb.jpg') no-repeat center center;
  background-size: cover;
  width: 100%;
  display: block;
}
<svg viewbox="0 0 100 25">
  <path fill="#9EAFFD" opacity="0.5" d="M0 30 V15 Q30 3 60 15 V30z" />
  <path fill="#9EAFFD" d="M0 30 V12 Q30 17 55 12 T100 11 V30z" />
</svg>
like image 72
web-tiki Avatar answered Oct 29 '22 13:10

web-tiki