我可以使用 font-size: calc(1px * 1vw) 来解决兼容性问题吗?
Can I use font-size: calc(1px * 1vw) to get around compatibility issues?
IE <= 8 不支持 font-size: 1vw
而我正在开发的网站需要我支持。
如果我calc(1px * 1vw)
,那return是一个像素值吗?我对calc()
的理解对吗?
我假设 font-sie: 1vw
不起作用,因为 IE 不知道如何将 vw
转换为 px
?
简短的回答是否定的,因为 IE <= 8 不支持 calc()
。https://caniuse.com/#search=calc()
稍微长一点的答案仍然是否定的,因为你不能乘以或除以不同的单位。这是 W3 文档所说的:
At *, check that at least one side is number. If both sides are integer, resolve to . Otherwise, resolve to the type of the other side.
At /, check that the right side is number. If the left side is integer, resolve to . Otherwise, resolve to the type of the left side.
(https://www.w3.org/TR/css3-values/#funcdef-calc)
因为 vw
不适用于 IE8(em
或 rem
也不行),我唯一能想到的就是尝试 %
.
如果您可以在 IE8 上使用静态字体大小,只需添加后备字体大小即可。这样现代浏览器将读取 1vw
并继续他们的一天,而 IE8 将读取它并说我是恐龙并且不知道那是什么,所以我将使用您以前的尺寸(例如16px
).
p {
font-size: 16px;
font-size: 1vw;
}
IE <= 8 不支持 font-size: 1vw
而我正在开发的网站需要我支持。
如果我calc(1px * 1vw)
,那return是一个像素值吗?我对calc()
的理解对吗?
我假设 font-sie: 1vw
不起作用,因为 IE 不知道如何将 vw
转换为 px
?
简短的回答是否定的,因为 IE <= 8 不支持 calc()
。https://caniuse.com/#search=calc()
稍微长一点的答案仍然是否定的,因为你不能乘以或除以不同的单位。这是 W3 文档所说的:
At *, check that at least one side is number. If both sides are integer, resolve to . Otherwise, resolve to the type of the other side.
At /, check that the right side is number. If the left side is integer, resolve to . Otherwise, resolve to the type of the left side.
(https://www.w3.org/TR/css3-values/#funcdef-calc)
因为 vw
不适用于 IE8(em
或 rem
也不行),我唯一能想到的就是尝试 %
.
如果您可以在 IE8 上使用静态字体大小,只需添加后备字体大小即可。这样现代浏览器将读取 1vw
并继续他们的一天,而 IE8 将读取它并说我是恐龙并且不知道那是什么,所以我将使用您以前的尺寸(例如16px
).
p {
font-size: 16px;
font-size: 1vw;
}