【问题标题】:CSS Multiple gradient glow from borderCSS多重渐变从边框发光
【发布时间】:2017-05-03 08:22:36
【问题描述】:

你好,我想用 CSS 做类似this 的设计。

我尝试使用here 描述的伪元素来制作它。 每次我都会遇到一个问题——只有一个渐变框阴影可用或无法为每个点分别设置发光的轮廓/边框。 我还尝试在椭圆渐变的帮助下阻止发光的轮廓:(

有人可以告诉我是否有一些独特的方法吗?

有我的code

.wrap{
  height: 20em;
  width: 15em;
  background: black;
}
.btn-t {
  position: relative;
  background: radial-gradient(ellipse at center, blue, blue);
  box-shadow: inset 0 0 0 5px #7B9DFF;
  color: $white-txt;
  height: 4em;
  line-height: 3.75em;
  margin: 1em;
  max-width: 10em;
  padding: 0.25em 1em;
  text-align: center;
  font-size: 20px;
  color: white;
}

.btn-t:after {
  content: '';
    position: absolute;
  width: 95%;
  height: 20%;
  top: 40%;
  right: 0;
  border-right: 5px solid red;
  border-left: 5px solid red;
 }


.btn-t:hover {
  text-shadow: 0px 0px 10px white;
    background: radial-gradient(ellipse at center,  #71B1F5, blue);
}

谢谢。

【问题讨论】:

  • colorzilla.com/gradient-editor 这可能对您的项目有用。
  • 我知道这个工具,但我不能将它设置在边界之外,以便在两个不同的地方产生发光效果。
  • 我也有渐变,但我使用的是 sass,所以它看起来像这样。 i.imgur.com/bTVtcVA.gif
  • 该页面中有几个按钮。你想做哪一个?
  • 第一个默认值和悬停。

标签: css


【解决方案1】:

我已经尝试过复制一些接近的东西(一个版本用于文本按钮,一个用于图标版本):

图标版本假定 FontAwesome 用于生成图标(因此引用了 .fa):

/* text button */
.btn-glow {
  border: 1px solid #354a40;
  background-color: #1e2120;
  padding: .5em .85em;
  transition: all 0.025s linear;
  color: #6c8678;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.75);
  font-size: .75em;
  font-weight: bold;
}
.btn-glow:hover {
  color: #e6fcf5;
  text-shadow: 1px 1px 1em #66977b;
  border-image: linear-gradient(90deg, #375345, #9afdcf, #375345) 10;
  background-image: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0.1) 100%);
}
.btn-glow:focus {
  color: #79c6a1;
  border-image: linear-gradient(90deg, #375345, #9afdcf, #375345) 10;
  background-image: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0.1) 100%);
  outline: none;
}
.btn-glow:active {
  color: #fff;
  text-shadow: 1px 1px 2em #9ee6bf;
  background-color: #406552;
  border-image: linear-gradient(90deg, #375345, #9afdcf, #375345) 10;
  background-image: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.25) 0%, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0.25) 100%);
}

/* icon version */
.btn-glow-large {
  border: 1px solid #354a40;
  background-color: #1e2120;
  padding: 1em;
  transition: all 0.025s linear;
}
.btn-glow-large .fa {
  color: #6c8678;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.75);
  transition: all 0.025s linear;
}
.btn-glow-large:hover {
  border-image: linear-gradient(#375345, #9afdcf, #375345) 10;
  background-image: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0.1) 100%);
}
.btn-glow-large:hover .fa {
  color: #e6fcf5;
  text-shadow: 1px 1px 1em #66977b;
}
.btn-glow-large:focus {
  border-image: linear-gradient(#375345, #9afdcf, #375345) 10;
  background-image: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0.1) 100%);
  outline: none;
}
.btn-glow-large:focus .fa {
  color: #79c6a1;
}
.btn-glow-large:active {
  background-color: #406552;
  border-image: linear-gradient(#375345, #9afdcf, #375345) 10;
  background-image: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.25) 0%, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0.25) 100%);
}
.btn-glow-large:active .fa {
  color: #fff;
  text-shadow: 1px 1px 2em #9ee6bf;
}

https://codepen.io/ablewhite/pen/gWRQLN?editors=1100#0

【讨论】:

  • 该死的,这看起来很整洁 .-) 暂时离开 css 但这太棒了,谢谢!对我来说最大的问题是将边框图像设置为左/右和上/下分开,但即使有一侧看起来也不错。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-05
  • 1970-01-01
  • 2021-11-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多