如何避免带有渐变边框的按钮在悬停时跳转

时间:2018-02-17 18:03:29

标签: css css3

我在下面的每个片段都有这个按钮格式,这是我从一个网站获得的(即我自己没有编码)。问题是它在悬停时反弹。我基本上只想用渐变替换蓝色边框线(悬停时没有位置/尺寸变化)。

有人可以向我指出我必须调整的内容吗?鉴于我有几个按钮,理解解决方案对我来说比仅修复此按钮更重要。

提前非常感谢!!

.geodir_submit_search {
color: #000;
    border: 2px solid blue;
    border-width: 2px;
    box-shadow: rgba(0, 0, 0, 0.4) 0px 0px 11px 5px;
    letter-spacing: 1px;
    text-transform: capitalize;
    background-color: rgba(255, 255, 255, 0.3) !important;
    border-radius: 3px;
    min-height: 0px;
    padding: 7px 10px !important;
    text-align: center;
}
.geodir_submit_search::after {
content: " Search";
font-size: 14px;
font-weight: bold;
letter-spacing: 2px;
font-family: 'Lato', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
.showFilters, .showFilters:visited {
        background-color: rgba(255, 255, 255, 0.3) !important;
        color: #000;
        max-width: 40px;
        border: 1px dashed rgb(255, 255, 255) !important;
}

.showFilters:before, .geodir_submit_search:before {
  content: attr(data-text);
  z-index: 1;
  border-radius: 2px;
}

@media screen and (-webkit-min-device-pixel-ratio:0) {
  showFilters:before {
    background: #4f4f4f;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }
}
.showFilters:hover, .geodir_submit_search:hover {
  border: none !important;
  background:
  linear-gradient(rgba(255,255,255,0.4),rgba(255,255,255,0.4)) 2px 2px/calc(100% - 4px) calc(100% - 4px),
  linear-gradient(135deg, #7b63f0, #3ad4c1) 0 0/100% 2px, /* top border */
  linear-gradient(135deg, #7b63f0, #3ad4c1) 0 0/2px 100%, /*left border*/
  linear-gradient(135deg, #3ad4c1, #36b7ee) 0 100%/100% 2px, /* bottom border */
  linear-gradient(135deg, #3ad4c1, #36b7ee) 100% 0/2px 100%; /* right border */
  background-repeat:no-repeat;
}

.active {
  background:
  linear-gradient(to right,rgba(255,255,255,1) 20%,red) 1px 1px/calc(100% - 2px) calc(100% - 2px) no-repeat, linear-gradient(135deg, #7b63f0, #3ad4c1, #36b7ee);
}

.active:before {
  color: #2084c3;
}

@media screen and (-webkit-min-device-pixel-ratio:0) {
  .active:before {
    background: linear-gradient(to right, #7b63f0 0%, #3ad4c1 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }
}
<button class="geodir_submit_search fa">&#xf002;</button>

3 个答案:

答案 0 :(得分:1)

替换

.showFilters:hover, .geodir_submit_search:hover { border: none !important; }

.showFilters:hover, .geodir_submit_search:hover { border-color: transparent !important; }

.geodir_submit_search {
  box-sizing: border-box;
  color: #000;
  border: 2px solid blue;
  border-width: 2px;
  box-shadow: rgba(0, 0, 0, 0.4) 0px 0px 11px 5px;
  letter-spacing: 1px;
  text-transform: capitalize;
  background-color: rgba(255, 255, 255, 0.3) !important;
  border-radius: 3px;
  min-height: 0px;
  padding: 7px 10px !important;
  text-align: center;
}

.geodir_submit_search::after {
  content: " Search";
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 2px;
  font-family: 'Lato', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

.geodir_submit_search:before {
  content: attr(data-text);
  z-index: 1;
  border-radius: 2px;
}

.geodir_submit_search:hover {
  border-color: transparent !important;
  background: linear-gradient(rgba(255, 255, 255, 0.4), rgba(255, 255, 255, 0.4)) 2px 2px/calc(100% - 4px) calc(100% - 4px), linear-gradient(135deg, #7b63f0, #3ad4c1) 0 0/100% 2px, /* top border */
  linear-gradient(135deg, #7b63f0, #3ad4c1) 0 0/2px 100%, /*left border*/
  linear-gradient(135deg, #3ad4c1, #36b7ee) 0 100%/100% 2px, /* bottom border */
  linear-gradient(135deg, #3ad4c1, #36b7ee) 100% 0/2px 100%;
  /* right border */
  background-repeat: no-repeat;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

<button class="geodir_submit_search fa">&#xf002;</button>

答案 1 :(得分:1)

签出this code,你需要在悬停时增加填充,一定数量的边框,在你的情况下为2px:

.showFilters:hover, .geodir_submit_search:hover {
  border: none !important;
  background:
  linear-gradient(rgba(255,255,255,0.4),rgba(255,255,255,0.4)) 2px 2px/calc(100% - 4px) calc(100% - 4px),
  linear-gradient(135deg, #7b63f0, #3ad4c1) 0 0/100% 2px, /* top border */
  linear-gradient(135deg, #7b63f0, #3ad4c1) 0 0/2px 100%, /*left border*/
  linear-gradient(135deg, #3ad4c1, #36b7ee) 0 100%/100% 2px, /* bottom border */
  linear-gradient(135deg, #3ad4c1, #36b7ee) 100% 0/2px 100%; /* right border */
  background-repeat:no-repeat;
  padding: 9px 12px !important;
}

答案 2 :(得分:1)

这是我使用渐变为边框的另一个想法,我们的想法是简单地使用CSS变量更改悬停时的颜色。

:root {
 --first-color:blue;
 --second-color:blue;
 --third-color:blue;
}

.geodir_submit_search {
  color: #000;
  border:none;
  border-width: 2px;
  box-shadow: rgba(0, 0, 0, 0.4) 0px 0px 11px 5px;
  letter-spacing: 1px;
  text-transform: capitalize;
  background: linear-gradient(rgba(255, 255, 255, 0.4), rgba(255, 255, 255, 0.4)) 2px 2px/calc(100% - 4px) calc(100% - 4px), 
  linear-gradient(135deg, var(--first-color), var(--second-color)) 0 0/100% 2px, /* top border */
  linear-gradient(135deg, var(--first-color), var(--second-color)) 0 0/2px 100%, /*left border*/
  linear-gradient(135deg, var(--second-color), var(--third-color)) 0 100%/100% 2px, /* bottom border */
  linear-gradient(135deg, var(--second-color), var(--third-color)) 100% 0/2px 100%;
  /* right border */
  background-repeat: no-repeat;
  border-radius: 3px;
  min-height: 0px;
  padding: 9px 12px !important;
  text-align: center;
}

.geodir_submit_search::after {
  content: " Search";
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 2px;
  font-family: 'Lato', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

.geodir_submit_search:before {
  content: attr(data-text);
  z-index: 1;
  border-radius: 2px;
}

.geodir_submit_search:hover {
    --first-color:#7b63f0;
 --second-color:#3ad4c1;
 --third-color:#36b7ee;
 
}
<button class="geodir_submit_search fa">&#xf002;</button>