CSS宽度减法 [英] CSS width subtraction
问题描述
如何在CSS中减去宽度?
How to subtract width in CSS?
例如:
width = 100% - 10px
width = 100% - 10px
我不是说填充或边距。
推荐答案
使用 calc 解决方案将是:
width: calc(100% - 10px);
Calc
可以用于加法,减法,乘法,除法。
Calc
can be use with Addition, Subtraction, Multiplication, Division.
注意:
注意:+和 - 运算符必须始终包含空格。
例如,calc(50%-8px)的操作数将被解析为
百分比,然后是负长度,无效表达式,而
calc的操作数(50%-8px )是一个百分比,后跟一个减
符号和长度。更进一步,calc(8px + -50%)被视为
长度,后跟加号和负百分比。 *和/
运算符不需要空白,但是为了一致性添加它是
,并且推荐。
Note: The + and - operators must always be surrounded by whitespace. The operand of calc(50% -8px) for instance will be parsed as a percentage followed by a negative length, an invalid expression, while the operand of calc(50% - 8px) is a percentage followed by a minus sign and a length. Even further, calc(8px + -50%) is treated as a length followed by a plus sign and a negative percentage. The * and / operators do not require whitespace, but adding it for consistency is allowed, and recommended.
这篇关于CSS宽度减法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!