Anyone who has read my articles recently knows that I am currently in charge of a WeChat mini-program project, during which I encountered many interesting things and some "weird ideas". The background of this article is that one morning I was looking at a bunch of Following the previous article [Analysis of yPicker components in WeChat applet custom component library and implementation of three-level linkage between provinces, cities and districts], I analyzed such an example - the custom implementation of three-level linkage between provinces, cities and districts. There are detailed codes in it, so I won’t say more here. Let’s talk about how to call it: This is what I thought at the time: on the one hand, it was out of consideration of "not writing too much in JavaScript", and on the other hand, because I used three variables to implement the province, city, and district respectively, JavaScript only paid attention to these three variables, such as the spaces or other things between them were all taken to the wxml file. Like this: <view class="departments location" bindtap="fixedshow"> <view class="depart_title">Location</view> <view wx:if="{{provinces&&citys&&areas}}" class="placeholder depart_content">{{provinces}} {{citys}} {{areas}}</view> <view class="placeholder depart_content befselect" wx:else>Please select your current location</view> <view class="desc">If there are any changes, please modify and submit again</view> </view> (Because the call involves subsequent changes, the only time you click the "Confirm" button in the pop-up window is when you assign the three variables to the three variables that appear in this code in the event - otherwise, as long as the change is made, whether you click Cancel or Confirm, the change will have already occurred, which is not appropriate!) Its layout is as follows: .departments{ width: 100%; height: 96rpx; display: flex; align-items: center; font-size: 36rpx; font-weight: 347; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; } .location{ position: relative; border-bottom: 1rpx solid rgba(0,0,0,.009); display: flex; align-items:flex-start; padding-top: 20rpx; } .desc{ position: absolute; right: 19rpx; bottom: 4rpx; color: rgb(63,142,255); font-size: 23rpx; } .departments .depart_title{ width: 20%; } .departments .depart_content{ margin-left: 10%; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; } .departments .placeholder{ width: 69%; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; } After deciding to replace the wx:if here, you should first think: what to replace it with? OK, thinking of this, you should be able to think of a CSS pseudo-class: <view class="departments location" bindtap="fixedshow"> <view class="depart_title">Location</view> <view class="placeholder depart_content">{{provinces}} {{citys}} {{areas}}</view> <view class="desc">If there are any changes, please modify and submit again</view> </view> Then add this pseudo-class to class - depart_content: .placeholder:empty::before{ content: "Please select your current location"; color: rgba(0,0,0,.6); } A blank! After consulting the information: The
The final solution is: connect the three variables with spaces in js, and then render them on the page! (In fact, this is a custom selector, and automatic positioning is just sending a request to Amap to obtain the province, city, and district fields. I won’t write the code...) At this point we will find one thing: above we not only used the empty pseudo-class, but also the before pseudo-element! In fact, this is very common - after all, only empty can't add content (it seems that throughout CSS, only pseudo-elements such as before and after can add content to the page, whether it is text or pictures) I think there are two areas that should be paid more attention to:
This feature is very useful. From the above, we can see that the biggest use of this pseudo-class is "field missing prompt"! This is very practical. Moreover, leaving this task to CSS can also reduce a lot of "(layout) burden", provide a better experience, and make maintenance easier! For example, when I optimized the project, I added a unified class name to all the requested fields: .ym-empty:empty::before{ content: "No data, please try again", display: block; text-align: center; color: rgba(0,0,0,.6); /** Other positioning and font change operations*/ } This concludes my article about the CSS pseudo-class: empty that caught my eye. For more information about the CSS pseudo-class empty, please search previous articles on 123WORDPRESS.COM or continue browsing the related articles below. I hope you will support 123WORDPRESS.COM in the future! |
<<: Introduction to Docker Quick Deployment of SpringBoot Project
>>: Set an icon for the website to be displayed on the far left of the browser tab
Perhaps when I name this article like this, someon...
Table of contents 1. Modular concept 2. Modulariz...
WeChat Mini Program - QR Code Generator Download:...
Copy code The code is as follows: <input type=...
1. Make sure the system has the required libaio s...
HTML5 is the next version of the HTML standard. M...
1.1 Download the binary installation package wget...
When key is not added to the v-for tag. <!DOCT...
This article shares the specific code of vue+echa...
Intro Introduces and collects some simple and pra...
In HTML, <, >, &, etc. have special mean...
Create Group Grouping is established in the GROUP...
Table of contents 1 Node.js method of sending ema...
Problem description: Copy code The code is as fol...
Table of contents The concept of affairs The stat...