css vw单位

As page layouts become more complex, developers require access to a greater range of measurements to bring their designs to life. Beyond the standard percentage widths, r/ems and pixels we’re used to, the new vw and vh measurements (and their related brethren, vmin and vmax) provide more powerful ways of describing adaptive designs that can often eliminate reams of @media breakpoint interventions.

随着页面布局变得越来越复杂,开发人员需要访问更大范围的度量以使他们的设计栩栩如生。 除了我们惯用的标准百分比宽度, r/ems和像素之外,新的vwvh测量值 (及其相关的brethren, vminvmax )还提供了更强大的描述自适应设计的方式,这些设计通常可以消除@media断点的数量干预。

超越百分比 (Getting Beyond Percentages)

Traditional CSS measurement systems create a few problems in web design:

传统CSS测量系统在Web设计中会产生一些问题:

  • Percentage measurements don’t always work as expected. Developers always have to keep margins in mind when sizing elements. Trying to use % height on the body doesn’t work as designers think it should. font-size: 50% makes text half its normal size, rather than creating a dynamic relationship between the text and its container element.

    百分比测量并非总是能按预期进行。 在确定元素大小时,开发人员始终必须牢记利润。 尝试使用身体上的% height不起作用,这是设计师认为应该的。 font-size: 50%使文本变成其正常大小的一半 ,而不是在文本与其容器元素之间建立动态关系。

  • It’s almost impossible to keep shapes perfect. Keeping an element perfectly square and responsive at the same time is very difficult.

    保持形状完美几乎是不可能的 。 保持一个元素完美的正方形并同时响应是非常困难的。

vw and vh go a fair way towards addressing all of these issues.

vwvh去朝着解决所有这些问题一个公平的方式。

保持完美的节奏 (Keeping Perfect Rhythm)

It’s very easy to make “perfect” shapes on web pages using vw and vh. To do so, you have to appreciate that vw and vh can be used in almost any CSS property that can take a length measurement. Therefore, if you want an element that is always 20% of the screen width and remains square no matter what the window size, you can apply the same vw value to both its width and height:

使用vwvh在网页上制作“完美”形状非常容易。 为此,您必须意识到vwvh可以在几乎所有可以进行长度测量CSS属性中使用。 因此,如果您希望元素始终为屏幕宽度的20%, 并且无论窗口大小如何都保持正方形,则可以将相同的vw值应用于其widthheight

div.twentysquare {background: #999;width: 20vw;height: 20vw;
}

(Try resizing the browser window to see the effect on the square).

(尝试调整浏览器窗口的大小以查看对正方形的影响)。

Using the same method, it would be easy to make a rectangle always be twice as high as it was wide, while scaling to the size of the browser window:

使用相同的方法,很容易使矩形始终是宽度的两倍,同时缩放到浏览器窗口的大小:

div.onetworect {width: 20vw; height: 40vw;
}

Sizing a banner to a “perfect” ratio in CSS would be as simple as:

在CSS中将横幅大小调整为“完美”比例将非常简单:

div.goldenrect {width: 100vw;height: 61.8vw;background: red;
}

Fitting "clamped" text inside a responsive box, always perfectly filling the space allotted to it with breaking into new lines would just be a matter of sizing the font in vw units.

在响应式框中放入“固定”文本,始终用新的行来完美填充分配给它的空间,这只是将字体设置为vw单位即可 。

翻译自: https://thenewcode.com/738/Create-Perfect-Responsive-Shapes-With-CSS-vw-Units

css vw单位

css vw单位_使用CSS vw单位创建完美的响应形状相关推荐

  1. vw 前端_一行css代码轻松实现前端响应式布局(vw+rem)

    大家知道rem可以用来做响应式布局,只是html元素上的font-size样式需要根据屏幕宽度来指定. 之前有用@media媒体查询,根据各种屏幕宽度写html的样式,也用过类似lib-flexibl ...

  2. vw 前端_前端常用开发单位-vw

    前端常用开发单位-vw 05-前端开发常用单位-vwvh *{ margin: 0; padding: 0; } /*div{*/ /* width: 10vmin;*/ /* height: 10v ...

  3. css覆盖规则_条件 CSS

    在CSS的世界中,总是有很多实验性的属性先行,正因为这些先行者在不断的探索新的特性,才让CSS越来越强大.而这些实验性的特性并没有立马得到众多浏览器的支持,为了能让这些实验性特性能在部分支持的浏览器上 ...

  4. css 绘制三角形_解释CSS形状:如何使用纯CSS绘制圆,三角形等

    css 绘制三角形 Before we start. If you want more free content but in video format. Don't miss out on my Y ...

  5. css flexbox模型_完整CSS课程-包括flexbox和CSS网格

    css flexbox模型 Learn CSS in this complete 83-part course for beginners. Cascading Style Sheets (CSS) ...

  6. html css 显示数值_【CSS纯技术】20.03.05-CSS渲染的原理

    今天学的东西信息量都很大,导致我总是要反复观看. 因为自己还没理解透,所以这一篇也不再追求大家能够看懂,只是用于帮助自己梳理头绪. 一.CSS如何计算数值? 在写CSS的过程中,我们会用px.em.r ...

  7. css 菜单栏悬停_在CSS中构建悬停菜单

    css 菜单栏悬停 A good menu design is an important part of any website or web app UI. Using only modern HT ...

  8. css svg使用_使用CSS使SVG响应

    css svg使用 An SVG can be embedded on a web page in many ways; one of which is embedding it inline in ...

  9. css 倒三角_改善CSS的10种最佳做法

    CSS似乎是一种非常简单的语言,很难在其中犯错误.你只需添加样式规则,就可以对网站进行样式设置了,对吗?对于只需要几个CSS文件的小型网站,情况可能就是这样.但是在大型应用程序中,样式可能会迅速失控. ...

最新文章

  1. UA MATH566 统计理论 证明UMVUE的方法
  2. mysql_group by与聚合函数、order by联合使用
  3. .NET Framework 4.8发布
  4. Android aidl在Framework的使用
  5. html div bgcolor,HTML body bgcolor transparent
  6. python中easygui有几种_Python 模块EasyGui详细介绍
  7. vue对象属性为null_如何避免在Vue中使用null作为class的空值
  8. 简单的MPI+Fortran95实现
  9. Word参考文献交叉引用——连续多项引用
  10. struts2架构网站漏洞修复详情与利用漏洞修复方案
  11. 《连线》杂志主编Kevin Kelly 给年轻人的99条人生建议
  12. 【JSP笔记02】JSP注释、脚本、表达式、JSP三大指令、JSP七大动作的介绍及使用
  13. 自动控制原理:如何用折线式伯德图计算截止频率?
  14. CSS list-style属性控制li标签样式
  15. 《算法新解》作者刘新宇:我只是想打开那些黑盒子,告诉人们里面有什么。
  16. android开机动画和图片在那个目录下,Android开机动画bootanimation.zip是怎么制作和使用的?...
  17. [C]奶牛生奶牛问题
  18. Cocos2D开发的iPhone游戏的教程
  19. My97DatePicker时间控件
  20. vue 判断两个时间插件结束时间必选大于开始时间

热门文章

  1. Java对接高德地图计算距离_高德地图计算两点之间的距离java+html
  2. python(7) - 发送、接收电子邮件
  3. 人工智能前沿——未来AI技术的五大应用领域
  4. 【Linux】Ubuntu下搜狗拼音输入法
  5. display:flex 常用
  6. 【教程】github学生包,可免费使用copilot
  7. 如何做微信分享抽佣以及分佣金
  8. pychram 配置清华镜像源_教你如何给树莓派更换软件源
  9. ffmpeg文档37-视频滤镜
  10. 华清远见上海中心22071班 8.24作业