Circle with curved edge

Asked

Viewed 458 times

11

I’ve been tasked to make a website, and I’m having trouble making a detail in CSS

I need to make a round edge that has a curved ending, so you understand better, I’ll show you photo and post my code

What I need (Photoshop) inserir a descrição da imagem aqui

What do I have inserir a descrição da imagem aqui

I would like a CSS solution, but I couldn’t

.bottom-bar {
  background: #29a7e8;
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 50px;
  text-align: center;
}

.circle {
  display: inline-block;
  position: relative;
  top: -10px;
  border-radius: 100%;
  background: #29a7e8;
  width: 60px;
  height: 60px;
  margin: 0 1rem;
}
<div class="bottom-bar">
  <div class="circle"></div>
  <div class="circle"></div>
  <div class="circle"></div>
</div>

  • I believe that a css solution does not exist, but rather using images

  • What you need is a CSS sinusoidal curve calculation, which fortunately exists, see this model: https://codepen.io/diessica/pen/keLBq

  • @Rogériodec actually this example is a swivel div hit one aligned to another... Note that with the SVG filter you have achieved this with a few lines and apply directly to the div. [] s

  • 1

    @Rogériodec by the way, this Pen you posted is from one of the people who has been with us since the "beginning" of Sopt: https://answall.com/users/1089/ :)

2 answers

8


Using the Filters of SVG I believe that you get a result very close to the image. I will not go into detail because the subject is extensive. But I left commented in the code where you control the intensity of the curvature enters the ball and bar. And below I leave some explanations.

inserir a descrição da imagem aqui

Note that the SVG tag has only the filter and filter settings. After defining them I used the filter:url(#filter) to call the filter on the bar and the elements inside. So I needed a div new on the outside (.base) to avoid distortions in the corners of the bar that will receive the filter.

To better understand see the example below. See also that it works from IE 10 forward: https://caniuse.com/#feat=svg-Filters

OBS: I left a background image and an animation at the end of the CSS just for you to see what the interaction of the filter effect is like between the elements. I know you don’t need the animation, but it’s just for teaching purposes, okay.

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}
.base {
    background: #29a7e8;
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 50px;
}
.bottom-bar {
    background: #29a7e8;
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 50px;
    text-align: center;
    filter: url(#filter);
}
.circle {
    display: inline-block;
    position: relative;
    top: -10px;
    border-radius: 100%;
    background: #29a7e8;
    width: 60px;
    height: 60px;
    margin: 0 1rem;
}
/* apenas exemplo */
.circle:nth-child(2) {
-webkit-animation: anima 2s infinite ease;
        animation: anima 2s infinite ease;
}
@-webkit-keyframes anima {
50% {
    top: -100px;
}
}
@keyframes anima {
50% {
    top: -100px;
}
}
body {
background: url(http://unsplash.it/600/400);
background-size: cover;
background-position: center;
overflow: hidden;
}
<div class="base">
    <div class="bottom-bar">
        <div class="circle"></div>
        <div class="circle"></div>
        <div class="circle"></div>
    </div>
</div>

<svg>
    <defs>
        <filter id="filter">
        <!-- aqui vc controla a curvatura entre a bola e a barra, deixei 5 para ficar acentuado e vc perceber, mas com 3 fica como vc quer mais suave -->
        <feGaussianBlur in="SourceGraphic" stdDeviation="5" result="blur"/> 
        <feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 19 -9" result="filter"/>
        <feComposite in="SourceGraphic" in2="filter" operator="atop"/>
        </filter>
    </defs>
</svg>

  • Thanks friend, helped too much, perfect solution!

  • @Yungsilva without problems my friend, success with the project, this svg filter artificial to do a lot of creative things!

  • 1

    I like this solution. You can explain a little more how this "Blending" of forms works in SVG?

  • 1

    @bfavaretto then, if you are removing the filters slowly you will understand a little better. First vc puts the Blur to make the "smoky" on the edges of the elements, then with the vector rgba matrix (1 0 0 0 0) vc adjusts the mask of a Blur entering the other, and with the Composite vc puts the two filters together. There is a lot of material on this with very technical explanations, look for Gooey Effect, MDN has technical material on all SVG filters tb. Here is an excellent article http://alistapart.com/article/finessing-fecolormatrix. with the diagram perfectly explained

4

You can create two pseudo-elements ::before and ::after curved (border-radius) on the lower edge (bottom) and position them at their corners.

See how it looks:

inserir a descrição da imagem aqui

Code:

.bottom-bar {
  background: #29a7e8;
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 50px;
  text-align: center;
}

.circle {
  display: inline-block;
  position: relative;
  top: -10px;
  border-radius: 100%;
  background: #29a7e8;
  width: 60px;
  height: 60px;
  margin: 0 1rem;
}

.circle::before,
.circle::after{
   content: '';
   background: #fff; /* mesma cor do fundo da página */
   padding: 1px 1px 0;
   width: 6px;
   height: 2px;
   position: absolute;
   border-bottom: 2px solid #29a7e8; /* borda inferior na cor azul */
   z-index: -1;
   top: 7px;
}

.circle::before{
   left: 2px;
   border-radius: 0 0 100% 0;
}

.circle::after{
   right: 2px;
   border-radius: 0 0 0 100%;
}
<div class="bottom-bar">
  <div class="circle"></div>
  <div class="circle"></div>
  <div class="circle"></div>
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.