Parse errors when using calc with rem and px
This is a known bug in w3 css validator:
https://www.w3.org/Bugs/Public/show_bug.cgi?id=18913
Why is calc not working with rem and px combined?
You just need to add a space around the minus operator:
.test {
background-color: gold;
max-width: calc(24rem - 13px);
}
<div class="test">I have a max width</div>
CSS3 calc() validation: Value Error : width Parse Error
This appears to be a bug in the validator. Your calc()
syntax is valid. Don't worry about it.
Whenever you need to validate your CSS, remove just that declaration so it does not cause irrecoverable parse errors.
W3C CSS validation error using calc() and vendor extensions
Don't worry about the vendor extensions. I don't recall why they are flagged that way but they are not errors on your part. I don't recall the reasoning for it. iirc, there is a checkbox to ignore these warnings.
The explanation may lie in this article where it states:
Vendor-specific extensions (mostly) do adhere to the CSS 2.1 grammar,
but since they are not defined in the CSS 2.1 specification, they are
invalid. Hence the CSS validator is correct in reporting them as
validation errors.
W3c validation error while using sass arithmetic operator
max-width: 1360px + 280px + 40px;
is not valid css. You can calculate the width in sass: max-width: 1360px + $paddingXL * 2 + 40px;
. Just remove #{}
.
height: calc(100%) not working correctly in CSS
You need to ensure the html and body are set to 100% and also be sure to add vendor prefixes for calc, so -moz-calc, -webkit-calc.
Following CSS works:
html,body {
background: blue;
height:100%;
padding:0;
margin:0;
}
header {
background: red;
height: 20px;
width:100%
}
h1 {
font-size:1.2em;
margin:0;
padding:0;
height: 30px;
font-weight: bold;
background:yellow
}
#theCalcDiv {
background:green;
height: -moz-calc(100% - (20px + 30px));
height: -webkit-calc(100% - (20px + 30px));
height: calc(100% - (20px + 30px));
display:block
}
I also set your margin/padding to 0 on html and body, otherwise there would be a scrollbar when this is added on.
Here's an updated fiddle
http://jsfiddle.net/UF3mb/10/
Browser support is:
IE9+, Firefox 16+ and with vendor prefix Firefox 4+, Chrome 19+, Safari 6+
Sass calculate percent minus px
Sass cannot perform arithmetic on values that cannot be converted from one unit to the next. Sass has no way of knowing exactly how wide "100%" is in terms of pixels or any other unit. That's something only the browser knows.
You need to use calc()
instead. Check browser compatibility on Can I use...
.foo {
height: calc(25% - 5px);
}
If your values are in variables, you may need to use interpolation turn them into strings (otherwise Sass just tries to perform arithmetic):
$a: 25%;
$b: 5px;
.foo {
width: calc(#{$a} - #{$b});
}
Related Topics
How to Give One CSS Class Priority Over Another
Ie Crossing Out Pseudo Element CSS
Detect Different Device Platforms Using CSS
How to Change Font-Color for Disabled Input
Run CSS3 Animation Only Once (At Page Loading)
Differencebetween Default, User and Author Style Sheets
Issue When Centering Vertically with Flexbox When Heights Are Unknown
How to Define a Class Name on Paragraph Using Markdown
Bootstrap - Removing Padding or Margin When Screen Size Is Smaller
Using @Font-Face with Rails 3.1 App
Chrome Issue with Background-Attachment Fixed and Position Fixed Elements
Label on the Left Side Instead Above an Input Field
How to Indicate Long Text into a Smaller Fixed Column with CSS
How to Center Multiple Inline-Block Elements with CSS
How to Inspect and Tweak :Before and :After Pseudo-Elements In-Browser