当前位置: 首页 > 知识库问答 >
问题:

CSS-渐变边框在safari中不起作用

宇文鸿振
2023-03-14

我正在尝试创建一个带有渐变边框的自定义按钮。此时,我得到了在Chrome和Firefox中工作的按钮。

我已经跟随了一个在线指导如何创建一个渐变的自定义边框,也是圆角的。指南的链接可以在这里找到:documentation。

但由于某些原因,相同的样式在Safari中不起作用。我不知道为什么会这样。

这里是我用来创建按钮的CSS代码。我还在底部包含了一个样式相同的片段。请注意,代码段有一些额外的类和CSS属性,只是为了使其正确显示。

.rainbow-gradient-border {
  position: relative;

  border-radius: 0.25rem;
  box-shadow: 0 2px 10px 0 rgba(142, 57, 255, 0.29);
}
.rainbow-gradient-border::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 0.25rem;
  padding: 0.1rem;
  background: linear-gradient(
    90deg,
    #4d3d8f 0%,
    #df67ed 23%,
    #e24c26 65%,
    #f18823 84%,
    #3aa6c2 100%
  );
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: destination-out;
  mask-composite: exclude;
}

null

body, .container{
 width: 100%;
 height: 100%;
 background-color: black;
}

.container{
 background-color: black;
}

.rainbow-gradient-border {
  position: relative;
  color: white;
  width: 10rem;
  
  display: flex;
  justify-content: center;
  align-items: center;
  
  border-radius: 0.25rem;
  box-shadow: 0 2px 10px 0 rgba(142, 57, 255, 0.29);
}
.rainbow-gradient-border::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 0.25rem;
  padding: 0.1rem;
  background: linear-gradient(
    90deg,
    #4d3d8f 0%,
    #df67ed 23%,
    #e24c26 65%,
    #f18823 84%,
    #3aa6c2 100%
  );
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: destination-out;
  mask-composite: exclude;
}
<div class="container">
  <div class="rainbow-gradient-border">
    <p>Log In</p>
  </div>
</div>

null

共有1个答案

樊浩初
2023-03-14

您可以通过更简单的方式实现这一点,而不需要使用掩码。我使用这个工具添加前缀。

null

   body, .container{
 width: 100%;
 height: 100%;
 background-color: black;
 color: white;
}

.rainbow-gradient-border {
  position: relative;
}

.outie{
  display: inline-block;
    background: -webkit-gradient(
    linear,
    left top, right top,
    from(#4d3d8f),
    color-stop(23%, #df67ed),
    color-stop(65%, #e24c26),
    color-stop(84%, #f18823),
    to(#3aa6c2)
  );
    background: -o-linear-gradient(
    left,
    #4d3d8f 0%,
    #df67ed 23%,
    #e24c26 65%,
    #f18823 84%,
    #3aa6c2 100%
  );
    background: linear-gradient(
    90deg,
    #4d3d8f 0%,
    #df67ed 23%,
    #e24c26 65%,
    #f18823 84%,
    #3aa6c2 100%
  );
  border-radius: 4px;
  padding: 2px;
  width: 10rem;
  border-radius: 0.25rem;
  -webkit-box-shadow: 0 2px 10px 0 rgba(142, 57, 255, 0.29);
          box-shadow: 0 2px 10px 0 rgba(142, 57, 255, 0.29);
}

.innie{
  display:inline-block;
  width: 100%;
  background: black;
  padding: 15px 0px;
  text-align: center;
}
<div class="container">
  <div class="rainbow-gradient-border">
    <span class="outie">
      <span class="innie">
        Log In
      </span>
    </span>
  </div>
</div>
 类似资料:
  • 问题内容: 我试图将渐变应用于边框,我认为这样做很简单: 但这是行不通的。 有人知道做边界渐变的正确方法是什么吗? 问题答案: WebKit现在(至少Chrome 12)支持渐变作为边框图像: Prooflink- 浏览器支持

  • 问题内容: 我的边框颜色有问题。没用 我是CSS新手, 问题答案: 默认情况下,is 和is 因此,您需要将它们设置为和。您可以将所有边框属性组合为一个,如下所示:

  • 我有一个SVG径向渐变可以在Chrome、Firefox甚至Internet Explorer中工作,但在Safari中不工作。你知道怎么在Safari里用这个吗? 下面是代码页:http://codepen.io/fractorr/pen/ovayvv

  • 主要内容:1. 线性渐变,2. 径向渐变,3. 圆锥渐变,4. 重复渐变CSS 中的渐变指的是两种或多种颜色之间的平滑过渡,以前我们必须使用事先定义好的图像来实现渐变效果,在 CSS3 出现以后则简单了很多,CSS3 为实现渐变效果提供了一种灵活的解决方案。 通过 CSS3 您可以定义三种类型的渐变,分别为线性渐变(通过 linear-gradient() 函数创建)、径向渐变(通过 radial-gradient() 函数创建)和圆锥渐变(通过 conic-grad

  • 问题内容: 要在元素上具有渐变背景,我需要执行以下操作: 现在,jQuery是否不打算消除与跨浏览器兼容性问题有关的所有工作?有没有更好的方法可以做到这一点。不使用任何其他插件? 问题答案: 有一个用于处理渐变的jQuery插件。我没用过,但是看起来很简单 http://plugins.jquery.com/project/gradient 继承人如何使用它: http://www.julien-

  • 主要内容:1. border-style,2. border-width,3. border-color,4. borderCSS 中的边框是围绕着元素内容和内边距的一条或多条线段,您可以自定义这些线段的样式、宽度以及颜色。您可以通过下面几个属性分别定义边框的样式、宽度和颜色: border-style:设置边框的样式,例如实线、虚线等; border-width:设置边框的宽度(厚度); border-color:设置边框的颜色; border:上面三个边框属性的缩写。 1. border-s