Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css/Less calc() method is crashing my IE10

I am trying to get a height in a div to be exactly 55px less then the parent div.

I tried to do this: height: calc(~"100% - 55px"); in less which creates this: height: calc(100% - 55px);

This works fine in Chrome and Firefox, but crashes on IE10.

It's not that it does not work but it crashes it. This is very strange i tried to find some info on line but can't see anything.

Also, this happens only with the height. If i were to use the calc() method on the width it runs fine.

Any idea on how i can get to the bottom of this?

like image 672
zawisza Avatar asked Oct 17 '13 09:10

zawisza


People also ask

What do you use CalC () for in CSS?

I used it to create a full-bleed utility class: .full-bleed { width: 100vw; margin-left: calc (50% - 50vw); } I’d say calc () is in my top 3 CSS things. I used it to make space for a sticky footer.

Can-MS-high-contrast-hack detect IE10 or IE11?

IE 10 can be targeted with the -ms-high-contrast-hack, but IE 11 cannot. I do not want to use JavaScript to detect the browser because this seems even hackier than using CSS hacks.

What is the best length of CSS to use with calc?

There are many lengths of CSS though, and they can all be used with calc (): Unitless numbers are acceptable too, for example line-height: calc (1.2 * 1.2); as well as angles like transform: rotate (calc (10deg * 5));.

What is calc() function in less?

This tutorial covers How to Compile LESS files and generates CSS files with tutorials with examples.. calc () is a function in CSS3 used to perform arthematics calculations on css attributes expression formed using arthematic operators and result value as output. The width is calculated as 80px for the given div in CSS.


2 Answers

I found the problem. There was a height:inherit inside one of the inside divs. Clearly IE gets super confused on this as the value is calculated and apparently not inheritable. All well now.

So in other words you can't do something like this:

<div style="height:100%">
  <div style="height: calc(100% - 50px)">
    <div style="height:inherit">
    </div>
  </div>
</div>

if you do IE10 will crash, here is an example : http://jsfiddle.net/wyRXp/1/

here i took out the inherit height: http://jsfiddle.net/wyRXp/2/ and it works fine.

Both above samples work fine in Firefox and Chrome

like image 194
zawisza Avatar answered Oct 18 '22 09:10

zawisza


There's a known issue with calc() in IE10

Internet Explorer (in accordance with the spec) does not accept calculations without spaces for additions/subtractions (ie. calc(100%-30px) is invalid, but calc(100% - 30px) works fine).

Refer to CanIUse.com.

Most probable reason of your crash is that the Less is removing spaces when escaping the value.

like image 39
matewka Avatar answered Oct 18 '22 08:10

matewka