WeChat applet layout example:
The following will be introduced in the following order:
Implementation of layout
Logic implementation
Implementation of styles
1. Implementation of layout
The largest layout is view. The view layout contains: a picture, text description, information bar and dividing line.
<!--最外层--> <view class="home-view1"> <!--图片层--> <view class="home-view2"> <image class="home-image1" src="http://qty83k.creatby.com/materials/origin/640e31829b8776967dedc670b5427d0f_origin.jpg"></image> </view> <!--描述层--> <text class="home-text1">小巧可爱的案头雅物小巧可爱的案头雅物小巧可爱的案头雅物小巧可爱的案头雅物小巧可爱的案头雅物</text> <!--信息层--> <view class="home-view3"> <view class="home-view4" > <image class="home-image-heart" src="http://qty83k.creatby.com/materials/origin/c5656ef00d38d89eae437c5a9102f8fa_origin.png"></image> <text class="home-text-heart bgColor" > 22</text> </view> <text class="home-text-time" >2016.10.29</text> </view> <!--分界线line--> <view class="home-view-line"></view> <!--图片层(下面的代码直接复制了上面的所有布局代码)--> <view class="home-view2"> <image class="home-image1" src="http://qty83k.creatby.com/materials/origin/640e31829b8776967dedc670b5427d0f_origin.jpg"></image> </view> <!--描述层--> <text class="home-text1">小巧可爱的案头雅物小巧可爱的案头雅物小巧可爱的案头雅物小巧可爱的案头雅物小巧可爱的案头雅物</text> <!--信息层--> <view class="home-view3"> <view class="home-view4" > <image class="home-image-heart" src="http://qty83k.creatby.com/materials/origin/c5656ef00d38d89eae437c5a9102f8fa_origin.png"></image> <text class="home-text-heart bgColor" > 22</text> </view> <text class="home-text-time" >2016.10.29</text> </view> <!--分界线line--> <view class="home-view-line"></view> </view>
2. Implementation of logic
Just registered the Page interface
Page({ data:{ } })
3. Implementation of styles
.home-view1 style: display specifies that the maximum View layout is a flexible layout, justify-content specifies that the content is centered and arranged vertically, …
.home-view3 style: display stipulates that the information bar layout is a flexible layout, and justify-content stipulates that the content is evenly distributed horizontally.
.home-view4 style: display specifies that the parent layout of collection pictures and collection numbers is a flexible layout, and align-items specifies that the content is centered in the vertical direction.
.home-image1 style: specifies the height of the image
.home-image-heart style: specifies the size of the collected pictures
.home-text1 style: specifies the style of the description text, text-align specifies the text to be centered, line-height specifies the height between two lines of text
.home-text-heart style: specifies the style of the collection number, border-radius specifies the border rounded corners
.home-view-line style: is a dividing line
.bgColor style: Specifies the background of the collection number
.home-view1{ display: flex; justify-content: center; flex-direction: column; height: 100%; width: 100%; margin: 6px; } .home-view3{ display: flex; justify-content: space-between; } .home-view4{ display: flex; align-items: center; } .home-image1{ height: 200px; } .home-image-heart{ width: 30px; height: 30px; } .home-text1{ text-align: left; line-height: 25px; margin-top: 6px; margin-right: 6px; color: gray; } .home-text-heart{ width: 22px; height: 22px; margin-left: 10px; border-radius: 20%; pad: 5px; text-align: center; } .home-text-time{ text-align: center; margin-right: 20px; padding-top: 5px; color: gray; } .home-view-line{ width: 100%; height: 6px; margin-top: 5px; background-color: gainsboro; } .bgColor{ background-color: lightblue; opacity: 0.6; }
Thanks for reading, I hope this helps everyone, and thank you for your support of this site!
For more articles related to WeChat applet simple DEMO layout, logic, and style exercises, please pay attention to the PHP Chinese website!