css-伪类选择器-:nth-child()-循环样式问题

本文探讨了如何使用CSS的:nth-child()伪类选择器来实现元素的循环样式。通过实例代码展示了如何精确地修改循环中的某个元素样式,为前端开发者提供了一种有效的方法来控制布局的视觉效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

循环样式:
在这里插入图片描述

目标样式:
在这里插入图片描述

代码如下:

<view class="grids">    
	<view class="grid" wx:for="{{icons}}" wx:for-item="icon" wx:key="icon.itemTypeId" data-item-type-id="{{icon.itemTypeId}}" data-type-name="{{icon.typeName}}" bindtap="toSercate">        
		<view class="grid__icon">          
			<image src=" {{icon.picUrl}}" data-id='{{icon.itemTypeId}}' binderror='errLoad'/>        
		</view>        
		<text class="grid__label">{{icon.typeName}}</text>    
	</view>  
</view>
.grids {    
	position: relative;    
	overflow: hidden;   
	margin: 20rpx 20rpx 0;   
	background-color: #ffffff;
}  
.grid {    
	position: relative;    
	float: left;    
	padding: 40rpx 20rpx;    
	width: 50%;    
	box-sizing: border-box;  
}  
.grid:nth-child(2n+1):before {    
	content: " ";    
	position: absolute;    r
	ight: 0;    
	top: 0;    
	width: 1rpx;    
	bottom: 0;    
	border-right: 1rpx solid #D9D9D9;    
	color: #D9D9D9;    
	transform-origin: 100% 0;    
	transform: scaleX(0.5);  
}  
.grid::after {
	content: " ";    
	position: absolute;    
	left: 0;    
	bottom: 0;    
    	right: 0;    
    	height: 1rpx;    
    	border-bottom: 1rpx solid #D9D9D9;    
    	color: #D9D9D9;    
    	transform-origin: 0 100%;    
    	transform: scaleY(0.5);  
}  
.grid:last-child:after {
    border-bottom: none;  
}  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值