html - margin-left : max(40px); and how does this works? 是什么意思

标签 html css sass

video中SASS教程,Gary写了一行CSS为:

 margin-left: max(40px);

我想了解这行代码的含义以及它是如何工作的?

此外,它在他的系统中运行良好,但在我的浏览器中不起作用。可能是什么原因?

enter image description here

Link to Gary's source code.

最佳答案

max()CSS 中的函数这是 CSS Values and Units Module Level 4 的一部分.

它允许您定义一个值列表,并使用其中的最大值:

margin-left: max(40px, 60px, 80px);

结果是:

margin-left: 80px;

也可以使用内部不带 calc 的表达式:

Note: Full math expressions are allowed in each of the arguments; there’s no need to nest a calc() inside! You can also provide more than two arguments, if you have multiple constraints to apply.

margin-left: max(10 * (1vw + 1vh) / 2, 12px);

不幸的是browser support对于 max() 以及 min()clamp() 并不那么广泛,此代码片段仅适用于 Safari 和 Chrome目前:

div {
  width: 10px;
  height: 10px;
  background: red;
  margin-left: max(40px, 200px); 
}
<div></div>

当您在 SASS 上下文中遇到此问题时,还值得注意的是,有一个 max()function in SASS以及。而且它比原生的还要老:

CSS added support for min() and max() functions in Values and Units Level 4, from where they were quickly adopted by Safari to support the iPhoneX. But Sass supported its own min() and max() functions long before this, and it needed to be backwards-compatible with all those existing stylesheets. This led for the need for extra-special syntactic cleverness.

关于html - margin-left : max(40px); and how does this works? 是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59190595/

相关文章:

html - Bootstrap 容器高度 100% 不起作用

jquery - 返回一个已经在窗口调整大小之前的元素

css - Eclipse/Aptana 中的 SASS 语法突出显示、代码完成和自动编译

javascript - HTML 间距问题 - 所有浏览器

html - 单击带有链接的元素时想要禁用大纲(无法在 Firefox 中使用)

html - 在 <nav> 上应用 css

css - 将页脚放在标题下方

internet-explorer - -ms-filter 圆 Angular CSS3 在 IE 中的效果?

css - scss\sass中*::selection{}怎么写?

html - 加载页面时将所有移动设备的图像居中