微信小程序 布局實例:
下面將會按照以下的順序介紹:
布局的實現
邏輯的實現
樣式的實現
1.布局的實現
最大的布局是view, view布局中包含了:一張圖片,文字描述,信息欄和分界線
<!--最外層--><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.邏輯的實現
只是注冊了Page界面
Page({ data:{ }})3.樣式的實現
.home-view1樣式:display規定最大View布局為彈性布局,justify-content規定內容居中,豎直排列, …
.home-view3樣式:display規定了信息欄布局為彈性布局,justify-content規定內容水平平均分配
.home-view4樣式:display規定了收藏圖片和收藏數的父布局為彈性布局,align-items規定內容在豎直方向居中
.home-image1樣式:規定圖片的高度
.home-image-heart樣式:規定收藏圖片的大小
.home-text1樣式:規定描述文字的樣式,text-align規定文字居中,line-height規定兩行文字之間的高度
.home-text-heart樣式:規定收藏數的樣式,border-radius規定邊界圓角
.home-view-line樣式:是一條分界線
.bgColor樣式:規定收藏數的背景
.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;}4.效果圖

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答