前端自定义按钮,设置边框移入抖动解决方案(带案例)

47 篇文章 0 订阅
46 篇文章 0 订阅

方案

解决方法:

第一种方法:是先将这个div设置一个跟背景颜色一样的边框,比如背景颜色为#aaa;那么你先设置这个div的样式:div
{border:1px solid #aaa;},然后再设置hover动作,div:hover { border:1px solid
red;} 。第二种方法:将这个div的border颜色设置为透明

案例

html

 <div class="main_right_btn_right1 main_right_btn_right2">Customize Shirts</div>

css

主要加下面这个样式,若移入有边框的话,移入前也要加边框,透明色,或者背景什么颜色,设置什么颜色,看下面实例

//下面这个是防止抖动样式
 border: 1px solid #fff;
 box-sizing: border-box !important;
overflow: hidden;
.main_right_btn_left1 {
  width: 157px;
  height: 52px;
  border-radius: 10px;
  background: #fdec57;
  text-align: center;
  line-height: 3;
  // 下面这个是防止选中文字
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
     // 这里也要加白色边框防止移入后有黑色边框距离差, 背景用什么颜色就用什么颜色边框,透明边框也可以 下面这两个样式至关重要!!!      border: 1px solid #fff; box-sizing: border-box !important;
      
  border: 1px solid #fff;
  // 下面这个是防止抖动样式
  box-sizing: border-box !important;
  overflow: hidden;
  -webkit-backface-visibility: hidden;
  -moz-backface-visibility: hidden;
  -ms-backface-visibility: hidden;
  backface-visibility: hidden;
  span {
    font-family: MicrosoftYaHeiLight;
    font-size: 16px;
    font-weight: 290;
    line-height: 24px;
    letter-spacing: 1px;
  }
}
.main_right_btn_left1:hover {
  width: 157px;
  height: 52px;
  border-radius: 10px;
  box-sizing: border-box;
  border: 1px solid #000000;
  background: none;
  text-align: center;
  line-height: 3;
  span {
    font-family: MicrosoftYaHeiLight;
    font-size: 16px;
    font-weight: 290;
    line-height: 24px;
    letter-spacing: 1px;
    /* Primary/Normal */
    color: #143a79;
  }
}
.main_right_btn_left2 {
  width: 156px;
  height: 52px;
  border-radius: 10px;
  box-sizing: border-box;
  border: 1px solid #000000;
  background: none;
  text-align: center;
  line-height: 3;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  span {
    font-family: MicrosoftYaHeiLight;
    font-size: 16px;
    font-weight: 290;
    line-height: 24px;
    letter-spacing: 1px;
  }
}

未加入前样式效果

 border: 1px solid #fff;
//下面这个是防止抖动样式
 box-sizing: border-box !important;
overflow: hidden;

请添加图片描述

加入后样式效果

请添加图片描述

最后

感觉文章好的话记得点个心心和关注和收藏,有错的地方麻烦指正一下,如果需要转载,请标明出处,多谢!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值