flex實現小程序導航新手教程。
實現示意:
1.鏈接頂部內邊距,留出圓形圖標的位置。
2.偽元素:before繪制圓形。
3.圓形中添加圖標。
4.左右外邊距控制間距,及促使在需要的地方換行。
如果需要字數限制的話:
資本
- .serviceMenu{
- display:flex;?//使用flex布局
- flex-wrap:wrap;?//子元素換行
- justify-content:center;?//子元素居中對齊
- padding:30rpx 0;?//留出上下邊距
- }
- .serviceMenu navigator{
- position:relative;?//為了絕對定位
- padding-top:120rpx;?//留出圓形圖標的位置
- flex-basis:140rpx;?//設定基礎寬度
- margin:15rpx;?//觸發換行位置(小程序會自動換算,不必考慮適配)
- text-align:center;
- font-size:24rpx;
- }
- //創建圖標
- .serviceMenu navigator:before{
- content:"/20";
- position:absolute;
- top:0;
- left:50%;
- margin-left:-55rpx;
- width:110rpx;
- height:110rpx;
- border-radius:50%;
- background:#bbc1cd;
- }
- //設定不同圖標。注意鏈接地址是絕對地址,因為小程序不支持相對地址的背景圖。只支持image相對地址。
- .serviceMenu navigator:nth-child(1):before{
- background:#fc6e51 url(https://xwbline.com/icon_service_big01.png) no-repeat center center;
- }
- .serviceMenu navigator:nth-child(2):before{
- background:#48cfad url(https://xwbline.com/icon_service_big02.png) no-repeat center center;
- }
- ………………
- text{
- display:block;
- overflow:hidden;
- white-space:nowrap;
- text-overflow:ellipsis;
- }
新聞熱點
疑難解答