【问题标题】:How to create a right triangle gradient如何创建直角三角形渐变
【发布时间】:2021-12-28 08:03:31
【问题描述】:

我正在尝试将其创建为渐变。 https://jsfiddle.net/ojscg6fn/

我这里有一个圆圈,如何创建一个直角三角形渐变放置在中间 圈子?

https://jsfiddle.net/79mjuhb2/

.play {
  -webkit-appearance: none;
  appearance: none;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  width: 90px;
  height: 90px;
  cursor: pointer;
  /*background:
    linear-gradient(green 0 0),
    linear-gradient(green 0 0)
    blue;*/
  background-size:7px 100%,100% 7px;
  background-position:center;
  background-repeat:no-repeat;
  border: 9px solid red;
  border-radius: 50%;
  transform: rotate(45deg);
  }
<button class="play" type="button" aria-label="Close"></button>

【问题讨论】:

    标签: css gradient linear-gradients


    【解决方案1】:

    HTML

    <button class="play" type="button" aria-label="Close">
      <div id="triangle-right"></div>
    </button>
    

    CSS

    .play {
      -webkit-appearance: none;
      appearance: none;
      box-sizing: border-box;
      margin: 0;
      padding: 0;
      width: 90px;
      height: 90px;
      cursor: pointer;
      /*background:
        linear-gradient(green 0 0),
        linear-gradient(green 0 0)
        blue;*/
      background-size:7px 100%,100% 7px;
      background-position:center;
      background-repeat:no-repeat;
      border: 9px solid red;
      border-radius: 50%;
      transform: rotate(0deg);
    }
    #triangle-right {
      width: 0;
      height: 0;
      border-top: 20px solid transparent;
      border-left: 20px solid red;
      border-bottom: 20px solid transparent;
      margin-left: 30px;
    }
    

    这是工作演示https://jsfiddle.net/rgn8wsbj/

    【讨论】:

      【解决方案2】:

      使用conic-gradient

      .play {
        -webkit-appearance: none;
        appearance: none;
        box-sizing: border-box;
        margin: 0;
        padding: 0;
        width: 90px;
        height: 90px;
        cursor: pointer;
        background: conic-gradient(from -135deg at right,red 90deg,#0000 0) 55% 50%/22px 44px no-repeat;
        border: 9px solid red;
        border-radius: 50%;
        }
      &lt;button class="play" type="button" aria-label="Close"&gt;&lt;/button&gt;

      【讨论】:

      • 如何使用线性渐变而不是圆锥来编写?你能提供一个线性的例子吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多