微笑小程序 1px边框border

像素基本概念: 参考这篇文章微信小程序----适配小结、移动端1px与选择器权重,里面已经很清楚的描述了像素单位及为什么会出现CSS写的1px,实际上看起来比1px粗。

直接上代码:

/* border 1px样式 */
.border_bottom, .border_top, .border_all {
  position: relative;
}

.border_top::after {
  position: absolute; 
  content: '';
  width: 100%;
  left: 0;
  top: 0;
  height: 1px;
  padding: 0 32rpx;
  box-sizing: border-box;
  background-color: #E6E6E6;
  -webkit-transform: scale(1, 0.5);
  transform: scale(1, 0.5);
  -webkit-transform-origin: center bottom;
  transform-origin: center bottom;
}

.border_bottom::after {
  position: absolute; 
  content: '';
  width: 100%;
  left: 0;
  bottom: 0;
  height: 1px;
  padding: 0 32rpx;
  box-sizing: border-box;
  background-color: #E6E6E6;
  -webkit-transform: scale(1, 0.5);
  transform: scale(1, 0.5);
  -webkit-transform-origin: center bottom;
  transform-origin: center bottom;
}

.border_all::before {
  content: '';
  display: block;
  position: absolute;
  width: 200%;
  height: 200%;
  border: 1px solid #d9d9d9;
  border-radius: 10rpx;
  transform-origin: 0 0;
  transform: scale(0.5, 0.5);  
  -webkit-transform: scale(0.5, 0.5);
  box-sizing: border-box;
}

此方法最好的地方是可以设置border-radius圆角,要注意的是效果有偏差时检查是否在.border_bottom, .border_top, .border_all中设置了display:flex;或者padding

微信小程序中,调整组件边框的显示效果可以通过使用 CSS 边框属性来实现。这些属性允许开发者对组件的上、下、左、右边框进行样式、颜色和宽度的设置。 对于整个组件边框的设置,可以使用 `border` 简写属性,它能够在一个声明中同时设置所有边框的样式、宽度和颜色。例如,如果想要给一个组件添加红色实线边框,可以使用如下代码: ```css border: 1px solid red; ``` 如果你需要更精细地控制每个边框,你可以分别使用 `border-top`, `border-right`, `border-bottom`, 和 `border-left` 属性。比如,要单独设置组件顶部边框为蓝色虚线,右侧边框为绿色点线,底部边框为黄色双线,左侧边框为紫色实线,可以这样编写代码: ```css border-top: 2px dashed blue; border-right: 3px dotted green; border-bottom: 4px double yellow; border-left: 1px solid purple; ``` 此外,为了创建更加美观的设计,还可以通过 `border-radius` 属性给组件添加圆角边框。此属性接受数字或百分比作为值,并且可以单独为四个角落指定不同的半径值,如 `border-top-left-radius`, `border-top-right-radius`, `border-bottom-left-radius`, 和 `border-bottom-right-radius` [^2]。例如,若想让组件的左上角和右下角呈现圆形,而其他两个角保持直角,可采用以下方式: ```css border-top-left-radius: 50%; border-bottom-right-radius: 50%; /* 其他角保持默认 */ border-top-right-radius: 0; border-bottom-left-radius: 0; ``` 当涉及到去除某些组件(比如按钮)自带的边框时,可以通过将 `border` 设置为 `none` 或者将其颜色设置为透明来达到目的。下面是一个去除了按钮边框的例子: ```css .contactBtn { border: none; border-color: transparent; /* 或者直接省略这行 */ background: none !important; } .contactBtn::after { border: none; background: none !important; } ``` 最后,如果你想自定义 tabBar 组件上边框的颜色,可以在全局样式文件 app.wxss 中添加特定的伪元素样式。例如,若希望将 tabBar 的线条颜色改为灰色,可以这样做: ```css page::after{ content:""; position:fixed; left:0; bottom:0; width:100%; height:2rpx; background-color:#EEEEEE; z-index:9999; } ``` 以上就是在微信小程序中实现或调整组件边框显示效果的方法概述。根据具体需求选择合适的属性组合,就可以创造出符合设计要求的效果了。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值