【问题标题】:Css Shape Creation Curved WaveCss 形状创建曲线波
【发布时间】:2014-04-12 19:15:55
【问题描述】:

This is what i have got so far After after checking out tutorial

  • 我想知道 div 上的弯曲效果是如何产生的
  • 上图折边效果是如何产生的

CSS

#MenuShape{
   height:50px;
   background-color:orange; 
   width:200px;
    position:relative;
    text-align:center;
    left:100px;

}
#MenuShape:after{
        content:"";
   position: absolute;
    width: 0;
   height: 0;
   left:200px;
  border-top: 50px solid transparent;
    border-left: 100px solid orange;
    border-bottom: 0px solid transparent;

}
#MenuShape:before{
        content:"";
   position: absolute;
    width: 0;
   height: -50;
   left:-100px;
  border-top: 50px solid transparent;
    border-right: 100px solid orange;
    border-bottom: 0px solid transparent;

}

HTML

<div id="MenuShape"  >
    sachin

</div>

https://css-tricks.com/这个网站在检查它时发现它的跨度被包裹 锚标记和 svg 标记

  <a href="/" class="home">
    <svg viewBox="0 0 100 25" class="shape-tab">
      <use xlink:href="#shape-tab"></use>
    </svg>

  <span>Blog</span></a>

Click here to see the unexpected behaviour it works fine in codepen

【问题讨论】:

  • 这样的事情通常是用一张图片来完成的。
  • css-tricks.com这个网站正在检查它
  • 嗯,您可以清楚地看到该网站使用了一个&lt;svg&gt; 元素......这基本上是一个(矢量)图像。
  • 其实,如果你想要那些特定的标签,它们的创建在this more recent tutorial中有详细说明。他们使用内联 SVG 图标。

标签: html css svg


【解决方案1】:

这是折叠角上的final demo (archived):

下面的代码是你如何创建它们的:

.note {
  position: relative;
  width: 30%;
  padding: 1em 1.5em;
  margin: 2em auto;
  color: #fff;
  background: #97C02F;
  overflow: hidden;
}

.note:before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  border-width: 0 16px 16px 0;
  border-style: solid;
  border-color: #fff #fff #658E15 #658E15;
  background: #658E15;
  -webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.3), -1px 1px 1px rgba(0, 0, 0, 0.2);
  -moz-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.3), -1px 1px 1px rgba(0, 0, 0, 0.2);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.3), -1px 1px 1px rgba(0, 0, 0, 0.2);
  /* Firefox 3.0 damage limitation */
  display: block;
  width: 0;
}

.note.rounded {
  -moz-border-radius: 5px 0 5px 5px;
  border-radius: 5px 0 5px 5px;
}

.note.rounded:before {
  border-width: 8px;
  border-color: #fff #fff transparent transparent;
  -moz-border-radius: 0 0 0 5px;
  border-radius: 0 0 0 5px;
}
&lt;div class="note"&gt;&lt;/div&gt;

要创建弯曲的波浪效果,您可以使用以下代码:

#wave {
  position: relative;
  height: 70px;
  width: 600px;
  background: #e0efe3;
}

#wave:before {
  content: "";
  display: block;
  position: absolute;
  border-radius: 100% 50%;
  width: 340px;
  height: 80px;
  background-color: white;
  right: -5px;
  top: 40px;
}

#wave:after {
  content: "";
  display: block;
  position: absolute;
  border-radius: 100% 50%;
  width: 300px;
  height: 70px;
  background-color: #e0efe3;
  left: 0;
  top: 27px;
}
&lt;div id="wave"&gt;&lt;/div&gt;

要获得曲线,您需要反转它的起点。按照相同的演示,只是颠倒你的价值观。

查看live demonstration (archived),了解边框半径如何创建您想要的形状和效果,并调整每个角以查看效果。

【讨论】:

  • 要准确更改您希望曲线对您的形状产生影响的位置,您需要使用您的值。特别是边框半径值...调整它们以获得您想要的曲线(左右下顶部等),以及您想要的曲线的戏剧性。
  • 如何将这种方法用于波浪作为全宽响应式背景?似乎不断变化的内部宽度会对在 :before 和 :after 中创建的椭圆造成严重破坏。
  • 不幸的是,由于静态值,这是不可能的。实现这一目标的唯一方法是使用媒体查询并针对不同的分辨率更改波形。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-10
  • 2017-03-14
  • 2021-11-19
  • 1970-01-01
  • 2021-05-17
相关资源
最近更新 更多