search
HomeWeb Front-endCSS TutorialHow can calc in css3 not be calculated when less is compiled?

This time I will show you how calc in css3 is not calculated when less is compiled. How calc in css3 is not calculated when less is compiled. What are the things to note?The following is a practical case, let’s take a look take a look.

For front-end ers, Less or Sass is already a necessary basic skill. With this tool, you can save a lot of coding time for front-end developers, allowing you to write CSS smoothly, and then Recently, I found some problems when adding calc to Less. I wrote this in Less:

p {width : calc(100% - 30px);}

As a result, Less executed this as an operation expression, and the result was analyzed to me like this:

p {width: calc(70%);}

I was depressed at that time. How could such a phenomenon happen? After various investigations, it was found that the calculation method of less overlapped with the calc method, and the two conflicted. So, I rewritten the writing method of calc in Less as follows:

p {width : calc(~"100% - 30px");}

OK, the analysis result Normal:

p {width: calc(100% - 30px);}

However, how to replace 30px with a variable?

  p {
  @diff : 30px;
  width : calc(~"100% - " + @diff);
  }

Written like this Webstorm did not report an error, but grunt-less reported an error:

C:\Users\zhong\WebstormProjects\test>grunt less

Running "less:development " (less) task

>> ParseError: Unrecognised input in style.less on line 4, column 2:

>> 3 @diff : 30px;

>> 4 width : calc(~"100% - " + @diff);

>> 5 }

Warning: Error compiling style.less Use -- force to continue.

Aborted due to warnings.

So I wrote:

  p {
  @diff : 30px;
  width : calc(~"100% - " @diff);
  }

Compiled successfully, but Webstorm always promptsSyntax error, although it can be compiled, but there is an error message when I look at the file, I feel bad

I feel bad, I have been searching for a long time and I still can’t find how to use WebstormDebuggingSyntax prompt error setting

So, I changed it to the following way of writing:

  p {
  @diff : 30px;
  width : calc(~"100% - @{diff}");
  }

This way of writing can be compiled and no errors are reported in Webstorm, so I prefer to use this way of writing. In this way, there will be no more problems. .

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

css3 animation sequence animation

How to use CSS weird box model and standard box model

The above is the detailed content of How can calc in css3 not be calculated when less is compiled?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
css怎么隐藏元素但不占空间css怎么隐藏元素但不占空间Jun 01, 2022 pm 07:15 PM

两种方法:1、利用display属性,只需给元素添加“display:none;”样式即可。2、利用position和top属性设置元素绝对定位来隐藏元素,只需给元素添加“position:absolute;top:-9999px;”样式。

sass软件是什么意思sass软件是什么意思Aug 15, 2022 am 11:39 AM

sass全称“Software as a service”,意思为“软件即服务”;它是一种软件部署模式,第三方供应商在云基础设施上构建应用程序,并以订阅的形式,通过互联网向客户提供这些应用程序,不要求客户预先建设底层基础设施。这意味着软件可以在任何有互联网连接和网络浏览器的设备上访问,而不像传统软件那样只能在本地机器上安装。

css3如何实现鼠标点击图片放大css3如何实现鼠标点击图片放大Apr 25, 2022 pm 04:52 PM

实现方法:1、使用“:active”选择器选中鼠标点击图片的状态;2、使用transform属性和scale()函数实现图片放大效果,语法“img:active {transform: scale(x轴放大倍数,y轴放大倍数);}”。

css3什么是自适应布局css3什么是自适应布局Jun 02, 2022 pm 12:05 PM

自适应布局又称“响应式布局”,是指可以自动识别屏幕宽度、并做出相应调整的网页布局;这样的网页能够兼容多个不同的终端,而不是为每个终端做一个特定的版本。自适应布局是为解决移动端浏览网页而诞生的,能够为使用不同终端的用户提供很好的用户体验。

css3动画效果有变形吗css3动画效果有变形吗Apr 28, 2022 pm 02:20 PM

css3中的动画效果有变形;可以利用“animation:动画属性 @keyframes ..{..{transform:变形属性}}”实现变形动画效果,animation属性用于设置动画样式,transform属性用于设置变形样式。

css3怎么设置动画旋转速度css3怎么设置动画旋转速度Apr 28, 2022 pm 04:32 PM

在css3中,可以利用“animation-timing-function”属性设置动画旋转速度,该属性用于指定动画将如何完成一个周期,设置动画的速度曲线,语法为“元素{animation-timing-function:速度属性值;}”。

css3线性渐变可以实现三角形吗css3线性渐变可以实现三角形吗Apr 25, 2022 pm 02:47 PM

css3线性渐变可以实现三角形;只需创建一个45度的线性渐变,设置渐变色为两种固定颜色,一个是三角形的颜色,另一个为透明色即可,语法“linear-gradient(45deg,颜色值,颜色值 50%,透明色 50%,透明色 100%)”。

css3怎么实现高度渐变效果css3怎么实现高度渐变效果Apr 28, 2022 pm 05:54 PM

实现方法:1、利用“元素{animation:名称 时间}”语句给元素绑定动画,并设置动画所需的时间;2、利用“@keyframes 名称{100%{height:渐变高度值;}}”语句,设置高度改变的动画动作,实现渐变效果即可。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)