【问题标题】:How to create this button shape CSS only?如何仅创建此按钮形状 CSS?
【发布时间】:2017-01-20 23:54:59
【问题描述】:

我很难回答如何使用 CSS 来执行此按钮。最简单的方法是在右侧部分使用带有背景图像的 :after,但这在悬停效果方面并不美观。

我已经能够通过右侧的蓝色箭头自己解决它,但是这个“双箭头”让我发疯了。

【问题讨论】:

标签: css button


【解决方案1】:

背景渐变可能吗?

button {
  margin:1em;
  border:none;
  padding:0.25em 3em 0.25em 1em;
  text-align:left;
  background:
    linear-gradient(-120deg, transparent 1em, #0099C3 1.05em , #0099C3 1.5em, transparent 1.45em, transparent 2em, #0099C3 2.05em) top no-repeat,
    linear-gradient(300deg, transparent 1em, #0099C3 1.05em , #0099C3 1.5em, transparent 1.45em, transparent 2em, #0099C3 2.05em) bottom no-repeat ;
  background-size: 100% 50%;
  color:white
}
<button>button button <br/> button</button>

【讨论】:

    【解决方案2】:

    这感觉有点笨拙,但确实有效。使用带有:before:after 伪元素的单个元素来创建箭头。该演示使用了max-width,可以根据使用情况进行更改。然而,高度可能需要保持固定才能工作。

    注意: V 形(白色箭头)延伸到条形的顶部/底部之外,并会与其他元素重叠,因此您需要使用 overflow: hidden 将此元素包装在另一个 div 中或制作一定要隔开其他元素,这样重叠不会影响相邻元素。

    .chevronlabel {
      background-color: #0099C3;
      max-width: 200px;
      height: 52px;
      display: inline-block;
      color: #ffffff;
      box-sizing: border-box;
      font-family: Arial;
      padding: 8px 30px 8px 12px;
      position: relative;
    }
    
    .chevronlabel:before {
      content: '';
      position: absolute;
      right: -13px;
      top: 0;
      width: 0;
      height: 0;
      border-top: 26px solid transparent;
      border-left: 13px solid #0099C3;
      border-bottom: 26px solid transparent; 
    }
    
    .chevronlabel:after {
      border-style: solid;
      border-color: #ffffff;
      border-width: 15px 15px 0 0;
      content: '';
      display: inline-block;
      height: 30px;
      width: 30px;
      position: absolute;
      top: 50%;
      right: -10px;
      transform: rotate(-45deg);
      vertical-align: top;
      transform: rotate(45deg) skew(20deg, 20deg) translate(-50%);
    }
    <div class="chevronlabel">
      Button Text and More Text
    </div>

    【讨论】:

      【解决方案3】:

      您可以使用 CSS 形状来做到这一点。

      另一种方法是内联 SVG。

      进一步阅读:https://css-tricks.com/working-with-shapes-in-web-design/

      【讨论】:

      • SVG 似乎是一个不错的方法,您应该在此处设置一个 sn-p 以避免您的答案被否决。以我自己的拙见,另一边的 CSS 形状不符合要求:)
      猜你喜欢
      • 2013-11-16
      • 2021-09-02
      • 2020-04-19
      • 1970-01-01
      • 2013-08-10
      • 2017-06-17
      • 2013-10-20
      • 2020-09-27
      • 1970-01-01
      相关资源
      最近更新 更多