边界弯曲的css - 弯曲的圆圈

时间:2018-05-18 01:19:15

标签: html css css3 svg border

我正在建立一个网站,我很难在CSS中做一个细节

我需要制作一个有弯曲结束的圆形边框,以便您更好地理解,我会显示照片并发布我的代码

我需要什么(Photoshop)

enter image description here

enter image description here

我想要一个CSS解决方案,但我不能。

这是我实际拥有的:

.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>

2 个答案:

答案 0 :(得分:1)

您可以使用SVG作为背景:

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

.circle {
  display: inline-block;
  position: relative;
  top: -28px;
  border-radius: 100%;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='10 10 45 15'  width='64' height='64' fill='#29a7e8'><path d='M12 24 L52 24 L52 16 C40 16 42 10 32 10 C20 10 22 16 12 16 Z' /></svg>") 0 0/100% 100% no-repeat;
  width: 60px;
  height: 60px;
  margin: 0 1rem;
}
&#13;
<div class="bottom-bar">
  <div class="circle"></div>
  <div class="circle"></div>
  <div class="circle"></div>
</div>


<svg xmlns='http://www.w3.org/2000/svg'
  viewBox='10 10 45 15'
  width='64' height='64'
  fill='#29a7e8'>
  <path d='M12 24 L52 24 L52 16 C40 16 42 10 32 10 C20 10 22 16 12 16 Z' />
</svg>
&#13;
&#13;
&#13;

对于仅CSS解决方案,您可以考虑使用径向渐变的组合来创建曲线:

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

.circle {
  display: inline-block;
  position: relative;
  top: -30px;
  background:
  radial-gradient(circle at top right,transparent 50%,#29a7e8 51%)100% 21px/12px 10px no-repeat,
  radial-gradient(circle at top left,transparent 50%,#29a7e8 51%)0 21px/12px 10px no-repeat,
  radial-gradient(circle at center,#29a7e8 55%, transparent 56%);
  width: 60px;
  height: 60px;
  margin: 0 1rem;
}
&#13;
<div class="bottom-bar">
  <div class="circle"></div>
  <div class="circle"></div>
  <div class="circle"></div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

通常,有多种方法可以创建这种形状,从简单到更复杂:

  • 使用radial-gradient添加2个伪元素。

    最简单且受支持的解决方案。可能是我会用的那个。

  • 使用mask-image添加2个伪元素(与上面相同,但是支持更差)。

    在代码方面,与预览版本非常相似,但带有really bad support(支持浏览器的需要浏览器前缀)。

    如果要检查它们的相似程度,请查看另一个类似的问题:CSS "inverse border-radius" outside element's bounding box to create a mobile phone notch design

  • 添加2个带有border-radiusbox-shadowbackground: transparent的伪元素。

    需要更多代码,但看起来至少在Chrome Version 78.0.3904.108上更流畅,尽管差异很小。无论如何,您可以做的形状不会像以前的替代方法那样复杂,尤其是如果您要使用椭圆而不是圆形的话,尤其如此。

  • 使用SVG。

    我认为SVG解决方案在这里不值得,但是对于更复杂的形状或动画/过渡形状来说,它是一个不错的选择。无论如何,Temani Afif已经使用SVG添加了解决方案。

要记住的一点是,就像导航栏一样,每个按钮的可悬停/可点击区域应与用户实际看到的内容尽可能匹配,Temani Afif并非如此的解决方案。

这就是使用radial-gradient的样子:

body {
  margin: 0;
  font-family: monospace;
  background: #DDD;
}

.bar {
  background: white;
  position: fixed;
  bottom: 0;
  width: 100%;
  height: 60px;
  text-align: center;
}

.circle {
  position: relative;
  top: -10px;
  border-radius: 100%;
  background: white;
  width: 60px;
  height: 60px;
  margin: 0 16px;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  font-size: 24px;
  font-weight: bold;
  color: black;
  transition: box-shadow ease-in 150ms;
  background: white;
  border: 0;
  outline: none;
}

.circle:hover {
  box-shadow: 0 16px 16px 0 rgba(0, 0, 0, .125);
}

.circle:active {
  box-shadow: 0 8px 8px 0 rgba(0, 0, 0, .125);
}

.circle::before,
.circle::after {
  content: "";
  position: absolute;
  top: 4px;
  width: 32px;
  height: 6px;
  background: white;
  z-index: 1;
}

.circle::before {
  left: -18px;
  background: radial-gradient(ellipse at 0% -25%, transparent 0, transparent 70%, white 70%, white 100%);
}

.circle::after {
  right: -18px;
  background: radial-gradient(ellipse at 100% -25%, transparent 0, transparent 70%, white 70%, white 100%);
}
<nav class="bar">
  <button class="circle">?</button>
  <button class="circle">?</button>
  <button class="circle">?</button>
</nav>

如果您想看到类似的问题以及所有替代方案,请查看以下内容:CSS "inverse border-radius" outside element's bounding box to create a mobile phone notch design

相关问题