Calculated css variables don't update in media queries [duplicate] - css

This question already has answers here:
Why does the Cascade for CSS Custom Properties Not Work? [duplicate]
(1 answer)
CSS scoped custom property ignored when used to calculate variable in outer scope
(2 answers)
Closed 4 years ago.
I've been working with some code that uses css variables where one of the variables derives it's value from a calc formula containing another variable (like the code below)
:root {
--parent-size: 20rem;
--child-size: calc(var(--parent-size) / 2);
}
...
#media (min-width: 768px) {
--parent-size: 30rem;
}
When var(--parent-size) change; var(--child-size) remains the same.
I'm assuming this might be a bug as it only affect variables with calculated values.
I've added a jsfiddle for reference here

Related

What does r-globalnav-height mean in a css file [duplicate]

This question already has an answer here:
What do these double-dash-prefixed CSS properties do? [duplicate]
(1 answer)
Closed 5 months ago.
I have seen a site styling
html
{
--r-globalnav-height: 44px;
}
what does this mean?
It is CSS variable. It can contain specific values to be used multiple times in a style sheets.
You can then use the variable from your example as follows:
nav {
height: var(--r-globalnav-height); /* height: 44px */
}
You can read more at Using CSS custom properties (variables) - MDN

what does --height mean in Saas or CSS? [duplicate]

This question already has an answer here:
What do these double-dash-prefixed CSS properties do? [duplicate]
(1 answer)
Closed 2 years ago.
I looked in an ionic project, there are some styles defined like below:
.modal{
padding: .4rem .2rem;
--border-radius:10px;
--background:black;
--height:3rem;
}
What does prefix '--' mean in Saas or CSS?
The '--' notation in css mark the declaration of a new variable.
The following is from this page: https://www.w3schools.com/css/css3_variables.asp
Variables in CSS should be declared within a CSS selector that defines its scope. For a global scope you can use either the :root or the body selector.
The variable name must begin with two dashes (--) and is case sensitive!
Equal to the computed value of font-size on the root element. When specified on the font-size property of the root element, the rem units refer to the property’s initial value.

forcing emCalc in calc css property [duplicate]

This question already has answers here:
Sass Variable in CSS calc() function
(6 answers)
Closed 8 years ago.
Is there anyway to force emCalc to run in Foundation. For example I have this code.
.rule {
height: calc(100% - emCalc(10px));
}
The sass simple produces exactly that, without running the emCalc function. Is there anyway to force the sass processor to run the emCalc function first?
You can do it like this:
.rule {
height: calc(100% - #{emCalc(10px)});
}

Multiple tags in 1 sass block [duplicate]

This question already has answers here:
Append the parent selector to the end with Sass
(1 answer)
Using SASS & reference for OOCSS
(1 answer)
Closed 8 years ago.
I have a class named button_class. Now a button or an input tag could have this class. Now using sass, I need to add something to the css if the tag name is input. Like this:
.button_class {
display: inline-block;
/* something like this */
& input {
padding: 2px;
}
}
As you guessed, I don't know how to do that.
SASS syntax doesn't permit this yet. :(
&input gives
"input" may only be used at the beginning of a compound selector

Can CSS convert a string to integer? [duplicate]

This question already has answers here:
CSS values using HTML5 data attribute [duplicate]
(3 answers)
Closed 9 years ago.
I use attr(data-width) to get the data-width-attribute from some list-item's. I try to use these values to set the width of that element.
The problem is that css cannot handle strings as width/height-value.
e.g.:
<foo data-width='100%'></foo>
/* can not work */
foo {
width: attr(data-width)
}
so I need to convert the value from the data-attribute to an integer (+unit).
Is that somehow possible?
No. And you cannot use an attr(...) construct as the value of a normal property, only in the value of a content property.
Instead of data-width attributes, you could use just style attributes. Not ideal, but more logical than to use data-* attributes to carry style info.
not without a precompiler and SASS / SCSS mixins

Resources