css-calc

CSS Variables - How to concatenate a minus symbol with CSS Variable in a calc()

ぐ巨炮叔叔 提交于 2019-11-28 01:58:47
Hi so let me start by showing you how I would do this in SCSS: $submenu-padding-left: 1.5em; transform: translateX(calc(-#{$submenu-padding-left} + .5em)); which would compile to: transform: translateX(calc(-1.5em - .5em)) Basically SCSS allows me to concatenate a minus symbol - with a variable in order to convert it to a negative value. Is it possible to achieve this with CSS Variables? Yes you can do it. Simply multiply by -1 : :root { --margin-l: 50px; } body { padding: 0 100px; border:1px solid; } .box-1 { background: red; height: 100px; width: 200px; margin-left: calc(-1 * var(--margin-l)

CSS Calc Viewport Units Workaround?

自作多情 提交于 2019-11-27 11:45:51
From what I've seen in other answers , CSS viewport units can't be used in calc() statements yet. What I would like to achieve is the following statement: height: calc(100vh - 75vw) Is there some workaround way I can achieve this using purely CSS even though the viewport units can't be used in the calc() statement? Or just CSS and HTML? I know I can do it dynamically using javascript, but I'd prefer CSS. Danield Before I answer this, I'd like to point out that Chrome and IE 10+ actually supports calc with viewport units. FIDDLE (In IE10+) Solution (for other browsers): box-sizing 1) Start of

calc() not working within media queries

こ雲淡風輕ζ 提交于 2019-11-27 04:57:09
@media screen and (max-width: calc(2000px-1px)) { .col { width: 200px; } } The value after subtraction should be 1999px , however it does not seem to be working. If I manually change it to 1999px it works fine, so I know it's not a problem with my CSS. Is calc not supported within media queries, or am I doing something wrong? ANSWER WAS EDITED 13.02.2018: Using calc in media queries is supported by the spec, but support was only implemented by browsers recently (February 2018). Currently, calc in media queries is supported by Safari Technology Preview 49+ , Chrome 66+ , and Firefox 59+ . See

How do I debug CSS calc() value?

时间秒杀一切 提交于 2019-11-26 18:32:12
问题 I have relatively complex formulas e.g. transform: scale(var(--image-scale)) translateY(calc((1px * var(--element-height) * (var(--image-scale) - 1)) / 2 * var(--scrolled-out-y))) how do I debug calculated value? moreover is there a way to validate/highlight formulas errors? I tried to output like this to the pseudoelement but no luck position: fixed; display: block; left:0; right: 0; background: yellow; padding: 5px; z-index: 100; content: calc((1px * var(--element-height) * (var(--image

Using calc() with tables

我的未来我决定 提交于 2019-11-26 16:47:18
I'm trying to get a table with fixed-width td s and variable-width td s. Im using the CSS calc() function, but somehow it seems like I can't use % in tables. So that is what I have so far: <table border="0" style="width:100%;border-collapse:collapse;"> <tr style="width:100%"> <td style="width:30px;">1</td> <!--Fixed width--> <td style="width: calc( (100% - 230px) / 100 * 40);">Title</td> <!--Width should be 40% of the remaining space--> <td style="width: calc( (100% - 230px) / 100 * 40);">Interpret</td> <!--Width should be 40% of the remaining space--> <td style="width: calc( (100% - 230px) /

CSS Calc Viewport Units Workaround?

三世轮回 提交于 2019-11-26 15:44:23
问题 From what I've seen in other answers, CSS viewport units can't be used in calc() statements yet. What I would like to achieve is the following statement: height: calc(100vh - 75vw) Is there some workaround way I can achieve this using purely CSS even though the viewport units can't be used in the calc() statement? Or just CSS and HTML? I know I can do it dynamically using javascript, but I'd prefer CSS. 回答1: Before I answer this, I'd like to point out that Chrome and IE 10+ actually supports

CSS Calc alternative

耗尽温柔 提交于 2019-11-26 15:03:25
I am trying to dynamicly change the width of a div using CSS and no jquery. The following code will work in the following browsers: http://caniuse.com/calc /* Firefox */ width: -moz-calc(100% - 500px); /* WebKit */ width: -webkit-calc(100% - 500px); /* Opera */ width: -o-calc(100% - 500px); /* Standard */ width: calc(100% - 500px); I want also support IE 5.5 and higher , i found the following: expression. Is this the correct usage: /* IE-OLD */ width: expression(100% - 500px); Can I also support Opera and the Android browser? Danield Almost always box-sizing: border-box can replace a calc rule

How can I get a negative value of a CSS variables in a calc() expression?

醉酒当歌 提交于 2019-11-26 14:44:03
问题 Let me start by showing you how I would do this in SCSS: $submenu-padding-left: 1.5em; transform: translateX(calc(-#{$submenu-padding-left} + .5em)); which would compile to: transform: translateX(calc(-1.5em - .5em)) Basically SCSS allows me to concatenate a minus symbol - with a variable in order to convert it to a negative value. Is it possible to achieve this with CSS Variables? 回答1: Yes you can do it. Simply multiply by -1 : :root { --margin: 50px; } body { margin: 0 100px; border:1px

calc() not working within media queries

白昼怎懂夜的黑 提交于 2019-11-26 11:24:21
问题 @media screen and (max-width: calc(2000px-1px)) { .col { width: 200px; } } The value after subtraction should be 1999px , however it does not seem to be working. If I manually change it to 1999px it works fine, so I know it\'s not a problem with my CSS. Is calc not supported within media queries, or am I doing something wrong? 回答1: ANSWER WAS EDITED 13.02.2018: Using calc in media queries is supported by the spec, but support was only implemented by browsers recently (February 2018).

Sass Variable in CSS calc() function

流过昼夜 提交于 2019-11-26 09:14:30
问题 I\'m trying to use the calc() function in a Sass stylesheet, but I\'m having some issues. Here\'s my code: $body_padding: 50px body padding-top: $body_padding height: calc(100% - $body_padding) If I use the literal 50px instead of my body_padding variable, I get exactly what I want. However, when I switch to the variable, this is the output: body { padding-top: 50px; height: calc(100% - $body_padding); } How can I get Sass to recognize that it needs to replace the variable within the calc