css calc函数用法_CSS calc()函数

css calc函数用法

The calc() function lets you perform basic math operations on values, and it’s especially useful when you need to add or subtract a length value from a percentage.

calc()函数可让您对值执行基本的数学运算,当您需要从百分比中添加或减去长度值时,该功能特别有用。

This is how it works:

它是这样工作的:

div {
	max-width: calc(80% - 100px)
}

It returns a length value, so it can be used anywhere you expect a pixel value.

它返回一个长度值,因此可以在期望像素值的任何地方使用。

You can perform

你可以表演

  • additions using +

    使用+加法

  • subtractions using -

    使用-减去

  • multiplication using *

    *相乘

  • division using /

    除法使用/

One caveat: with addition and subtraction, the space around the operator is mandatory, otherwise it does not work as expected.

一个警告:加减法运算符周围的空间是强制性的,否则将无法正常工作。

Examples:

例子:

div {
	max-width: calc(50% / 3)
}
div {
	max-width: calc(50% + 3px)
}

翻译自: https://flaviocopes.com/css-calc/

css calc函数用法

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值