当前位置:   article > 正文

微信小程序中好看的按钮样式(渐变色)、view的点击变色效果、按钮漂亮的圆角边框、解决hover设置失效_好看的小程序按钮代码

好看的小程序按钮代码

好看1:

.wxss

  1. /* 从上往下渐变 */
  2. .bt_1{
  3. margin-top: 40rpx;
  4. background: linear-gradient(#ccfbff, #ef96c5);
  5. }

好看2:

.wxss

  1. /* 从左往右渐变 */
  2. .bt_2{
  3. margin-top: 40rpx;
  4. background: linear-gradient(to right, #ead6ee, #a0f1ea);
  5. }

好看3:

.wxss

  1. /* 对角渐变 */
  2. .bt_3{
  3. margin-top: 40rpx;
  4. background: linear-gradient(to bottom right, #eebd89, #d13abd);
  5. }

好看4:

.wxss

  1. /* 半透明渐变 */
  2. .bt_4{
  3. margin-top: 40rpx;
  4. background: linear-gradient(rgb(252, 126, 67), rgba(255,0,0,0));
  5. width: 80%;
  6. border-radius: 50rpx;
  7. /* background: bg_red; */
  8. }

 

好看5:

在.wxss文件中代码如下:

  1. /* border-radius: 98rpx;是控制按钮边变圆 */
  2. .goodbutton {
  3. margin-top: 30px;
  4. width: 80%;
  5. background-color: rgb(252, 126, 67);
  6. color: white;
  7. border-radius: 98rpx;
  8. background: bg_red;
  9. }
  10. /* 按下变颜色 */
  11. .hover {
  12. top: 3rpx;
  13. background: rgb(236, 179, 156);
  14. }

在.wxml文件中的代码如下:

<button class='goodbutton'  hover-class="hover">激活</button>

好看6:

.wxss

  1. /* 多色渐变 */
  2. .bt_6{
  3. margin-top: 40rpx;
  4. background: linear-gradient(to right,#f9957f, #f2f5d0, #aebaf8, #c973ff );
  5. width: 80%;
  6. border-radius: 50rpx;
  7. }

 

第二种方式:漂亮的圆角边框和点击变颜色效果(view的点击效果也是这样实现)

  1. .bt_connect{
  2. width: 200rpx;
  3. height: 70rpx;
  4. color: #6699FF;
  5. border: 3rpx solid #6699FF;
  6. border-radius: 80rpx;
  7. font-size: 35rpx;
  8. margin-top: 40rpx;
  9. display: flex;
  10. justify-content: center;
  11. align-items: center;
  12. }
  13. /* 按钮的点击效果 */
  14. .hover-class-1 {
  15. top: 3rpx;
  16. background-color: #e7f5ff;
  17. }

在.wxml文件中的代码如下:

<button class="bt_connect" hover-class="hover-class-1" bindtap="connect">连接</button>

wxss代码:

  1. .btn {
  2. display: inline-block;
  3. margin: 20px;
  4. padding: 1em 2em;
  5. background: transparent;
  6. border: 2px;
  7. border-radius: 3px;
  8. font-weight: 400;
  9. text-align: center;
  10. box-shadow: 0px 2px 4px #67c0f0,0px 1px 2px #bf2fcb;
  11. }
  12. .btn text {
  13. background: -webkit-linear-gradient(left, #67c0f0, #bf2fcb);
  14. -webkit-background-clip: text;
  15. -webkit-text-fill-color: transparent;
  16. }

wxml代码:

  1. <view class="btn blue">
  2. <text>Buy Tickets Now</text>
  3. </view>

 

 

9种好看的渐变色网址:https://baijiahao.baidu.com/s?id=1644345842477287270&wfr=spider&for=pc

https://baijiahao.baidu.com/s?id=1643628153687951381&wfr=spider&for=pc

 

最后补充一种

background: linear-gradient(to right, #0385f5, #17b4bd);

解决hover设置失效

添加 !important,如下:

  1. .hover-ship {
  2. color: rgb(235, 107, 107) !important;
  3. }

解决在"style": "v2"环境中 设置按钮宽度失效

width: 500rpx !important;

加入!important即可

解决有时候会有一个很小的边框

border: none;

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/279612
推荐阅读
相关标签
  

闽ICP备14008679号