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
  • 技巧:
  1. 默认list的高度固定,overflow:hidden;当有锚点#some-anchor, 高度auto;
  2. 使用flexbox,自动换行flex-wrap: wrap,多行时自动隐藏
  3. control在list是一行时不显示,在list是多行(虽然高度是多行,但overflow:hidden 属性隐藏了多行)时,显示control,可以使用
    height: calc((2.25rem - 100%) * -1000)

    这样,当height: ((2.25rem - 4.5rem) * -1000) = 2250,这时max-height: 2.25rem便限制了,使得高度为2.25rem; 当100%<=2.25rem时(即宽度足够,一行显示),height: -number 就是0, 所以control就不显示了

  4. 利用el:target显示和隐藏control(more/less),先显示more,more设置一个锚点,也可以利用transition加上动画

/* Basic common settings: */
$primary-color: rgb(0,20,30);* {box-sizing: border-box;
}html {line-height: 1.25;font-family: 'Lato', sans-serif;
}/* The pattern: */.trunc-list-wrapper {height: 2.25em;overflow: hidden;padding-right: 3.5em;
}.trunc-list {list-style: none;display: flex;flex-wrap: wrap;margin: 0;padding: 0;position: relative;
}.trunc-list li {margin: 0;padding: 0;flex: 1 0 auto;
}.trunc-list a {display: block;padding: 0.5em;text-align: center;white-space: nowrap;color: #fff;background: $primary-color;
}.trunc-list a:hover,
.trunc-list a:active,
.trunc-list a:focus {background: lighten($primary-color, 10);
}.control {position: absolute;top: 0;right: -3.5em;width: 3.5em;height: calc((2.25em - 100%) * -1000);max-height: 2.25em;overflow: hidden;
}.control a {text-decoration: none;
}.control span {font-size: 0.75em;font-style: italic;
}.control--close {display: none;
}.trunc-list-wrapper:target {height: auto;
}.trunc-list-wrapper:target .control--open {display: none;
}.trunc-list-wrapper:target .control--close {display: block;
}

宽度足够时:

宽度不够时:

点击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

纯css实现responsive list -- 魔力calc相关推荐

  1. bootstrap4侧边栏_如何使用纯CSS和Bootstrap 4构建多个堆叠式粘性侧边栏

    bootstrap4侧边栏 In this tutorial you'll work on building multiple sticky sidebars that stack without u ...

  2. bootstrap4侧边栏_使用纯CSS和Bootstrap 4构建多个堆叠式粘性侧边栏

    bootstrap4侧边栏 Making high performant, pure CSS sticky sidebars that stack with Bootstrap 4. 制作与Boots ...

  3. before css 旋转_七夕,当然少不了纯CSS的点缀啦

    作者:JowayYoung 转发链接:https://mp.weixin.qq.com/s/pGAVZYvm3YGqnsJuc41shw 前言 以下程序猿通通指男性程序猿哈 今天是一年一度的七夕,估计 ...

  4. html怎么让方块自动旋转,如何使用纯CSS实现一个圆环旋转错觉的动画效果(附源码)...

    本篇文章给大家带来的内容是关于如何使用纯CSS实现一个圆环旋转错觉的动画效果,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 效果预览 源代码下载 https://github.com ...

  5. [css] 能不能使用纯css使你的浏览器卡死?怎么实现?

    [css] 能不能使用纯css使你的浏览器卡死?怎么实现? 可以,用计算属性calc,变量 个人简介 我是歌谣,欢迎和大家一起交流前后端知识.放弃很容易, 但坚持一定很酷.欢迎大家一起讨论 主目录 与 ...

  6. css怎样使弹跳的小球旋转,如何使用纯CSS实现小球跳跃台阶的动画效果(附源码)...

    本篇文章给大家带来的内容是关于如何使用纯CSS实现小球跳跃台阶的动画效果(附源码) ,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 效果预览 源代码下载 https://github ...

  7. 纯CSS实现移动端常见布局——高度和宽度挂钩的秘密

    纯CSS实现移动端常见布局--高度和宽度挂钩的秘密 不踩坑不回头.之前我在一个项目中大量使用css3的calc计算属性.写代码的时候真心不要太爽啊-可是在项目上线之后,才让我崩溃了,原因非常easy, ...

  8. html自动适应布局,用纯CSS实现自适应布局表格

    以手机.平板等移动设备为平台的浏览行为变得越来越平常,甚至有些人叫嚣PC将死.虽然说的有些夸张,但让你的网站布局能够兼容PC和移动设备这些需求变得越来越重要.这种网页布局就是"自适应布局&q ...

  9. css表格排序,纯CSS实现表格排序-利用CSS 变量和Flexbox

    1.引子 今天闲逛知名前端资讯站Front-End Front,发现一个比较有意思的效果,给大家分享下,希望可以对大家有所启发. 纯CSS实现表格排序 心急的同学,先看效果,我放在codepen上. ...

最新文章

  1. 2022-2028年中国打印耗材市场现状调研与进展趋势分析报告
  2. jQuery 表格插件汇总
  3. LeetCode:Remove Nth Node From End of List
  4. 虚拟机的网络连接模式
  5. c++ 协程_Python3 协程(coroutine)介绍
  6. java打印tomcat内存溢出_tomcat内存溢出问题监控工具
  7. Viliv N5 GPS安装及使用方法
  8. 面向公交营运管理的车路协同应用场景研究
  9. android pie原生壁纸,分享:全新谷歌Pixel 3原生手机壁纸 谷歌亲儿子的最强体验!...
  10. 爬虫项目#4567电影网scrapy数据爬取moviePro/持久化储存handReqPro
  11. 一款简洁的税后工资计算器(2019)
  12. Linux 之管道通信
  13. flvplayer.swfnbsp;flv视频播放器…
  14. k8s gc原理详解
  15. 人工智能、深度学习和机器学习有哪些区别?
  16. 携程和12306解绑
  17. JScrollPane设置滚动条自动到最下(或最右)
  18. js 监听esc按键
  19. 中国科学院大学计算机考研信息汇总
  20. 西门子S71200连接多功能电表

热门文章

  1. linux发行版本在这里。
  2. C++ 并行与分布式编程 chapter5 任务间并发的同步(2)
  3. jquery 开发总结(不断更新)
  4. struts+spring的配置方式总结
  5. 五个计算机软件,近五个交易日计算机软件概念股市复盘(4月19日)
  6. 路由器距离向量算法计算举例_距离向量路由选择是什么 距离向量路由选择原理介绍【图文】...
  7. Windows PE导出表编程3(暴力覆盖导出函数)
  8. hdu3460 字典树(打印机)
  9. 【数字信号处理】相关函数 ( 卷积与交换性 | 相关函数不具有交换性 | 推导过程 )
  10. 【错误记录】PyCharm 运行 Python 程序报错 ( SyntaxError: Non-ASCII character ‘\xe5‘ in file x.py on line 1, but )