纯css实现responsive list -- 魔力calc
生活随笔
收集整理的這篇文章主要介紹了
纯css实现responsive list -- 魔力calc
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
html:
<div class="trunc-list-wrapper" id="mylist"><ul class="trunc-list"><li><a href="#">A link</a></li><li><a href="#">Somewhere</a></li><li><a href="#">A bit longer</a></li><li><a href="#">Another one</a></li><li><a href="#">Yet another</a></li><li><a href="#">Again</a></li><li><a href="#">Last one</a></li><li aria-hidden="true" class="control control--open"><a href="#mylist"><span>more</span></a></li><li aria-hidden="true" class="control control--close"><a href="#"><span>less</span></a></li></ul> </div><p>Resize this frame to see the truncating effect.</p>?
css:?
- 要求:當頁面寬度足夠時,不顯示control(more / less),當小屏幕頁面寬度不夠時,顯示more,點擊后分行顯示所有item
- 技巧:
這樣,當height: ((2.25rem - 4.5rem) * -1000) = 2250,這時max-height: 2.25rem便限制了,使得高度為2.25rem; 當100%<=2.25rem時(即寬度足夠,一行顯示),height: -number 就是0, 所以control就不顯示了
利用el:target顯示和隱藏control(more/less),先顯示more,more設置一個錨點,也可以利用transition加上動畫
?
寬度足夠時:
?
寬度不夠時:
點擊more:
?
參考資料:https://www.sitepoint.com/responsive-css-patterns-without-media-queries/?utm_source=frontendfocus&utm_medium=email
轉載于:https://my.oschina.net/u/2510955/blog/870739
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的纯css实现responsive list -- 魔力calc的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: checkbox的常见问题
- 下一篇: 环境变量是什么?