css-variables

How to create color shades using CSS variables similar to darken() of SASS?

杀马特。学长 韩版系。学妹 提交于 2019-11-29 11:16:18
I'm looking a way of modifying a CSS variable as you would in SCSS Define a color like primary - and automatically I would get shades for focus and actives states. Basically, would like to change one variable in css variables and get 3 shades of the same color. What Id like to achieve in CSS $color-primary: #f00; .button { background: $color-primary; &:hover, &:focus { background: darken($color-primary, 5%); } &:active { background: darken($color-primary, 10%); } } trying to achieve: :root { --color-primary: #f00; --color-primary-darker: #f20000 // var(--color-primary) * 5% darker --color

Unable to overwrite CSS variable with its own value

匆匆过客 提交于 2019-11-29 11:05:46
Lets assume to have the following CSS: .box { width: var(--box-size); height: var(--box-size); border: 1px solid red; } .box--larger { --box-size: 66px; } .box--larger1 { --box-size: calc(var(--box-size) + var(--box--larger)); } .box--larger2 { --box-size: calc(50px + var(--box--larger)); } :root { --box-size: 50px; --box--larger: 16px; } <div class="box">1</div> <div class="box box--larger">2</div> <div class="box box--larger1">3</div> <div class="box box--larger2">4</div> I wonder why boxes 1 and 2 work but box 3 doesn't. I would expect box 3 to look the same as box 2 but it doesn't. I

Unable to get CSS variables working in Chrome 34

白昼怎懂夜的黑 提交于 2019-11-29 09:42:09
I previously asked a very similar question for an older version of Chrome. However, I am again having a hard time getting CSS variables to work, this time in Chrome 34 (Version 34.0.1847.131 m) on Windows 7. (Have not attempted on other OSes.) I see that the syntax has been changed (for the old one, see the question linked above) and the new one is what is currently in the CSS Variables spec. : :root { --main-color: #06c; --accent-color: #006; } /* The rest of the CSS file */ h1#foo { color: var(--main-color); } It's also important to note, I do have the Enable experimental Web platform

CSS Variables don't work in Microsoft Edge [duplicate]

大城市里の小女人 提交于 2019-11-28 14:28:22
This question already has an answer here: Do CSS variables work differently in Microsoft Edge? 1 answer I am designing a new blogger Template. I want to make it easy to change the whole template color at the same time by changing the value of the variable , so I used these lines: :root { --bg-color: #fff; --url-color : #000; --main-color : #2daeeb; --main-hover-color : #2ca1de; --alt-color : #ff6347; } but unfortunately it doesn't work in Edge browser, even though I used the prefix: -webkit- mhatch CSS variables are not supported by IE nor will they ever be. Update: CSS variables are supported

How do I debug CSS calc() value?

北战南征 提交于 2019-11-28 12:16:32
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-scale) - 1)) / 2 * var(--scrolled-out-y)); the only way I found is to put part of calculation to unused

Is there a difference between CSS custom properties and CSS variables?

泪湿孤枕 提交于 2019-11-28 08:11:10
问题 In all of the material I've read online, it appears that CSS custom properties and CSS variables are the same thing. However, at the end of an example in the Inheritance of CSS Variables section of the Mozilla Developer Network documentation, there is this confusing statement: Keep in mind that these are custom properties, not actual CSS variables. The value is computed where it is needed, not stored for use in other rules. For instance, you cannot set a property for an element and expect to

How to use commas in a CSS variable fallback?

时光怂恿深爱的人放手 提交于 2019-11-28 08:06:32
问题 How can one use commas in the fallback value of a CSS variable? E.g. this is fine: var(--color, #f00) , but this is weird var(--font-body, Verdana, sans-serif) . The idea is to be able to set a font-family using a variable with a fallback value of say Verdana, sans-serif . Edit: This actually works pretty well for browsers that support CSS properties, but the issue seems to come from Google Polymer's polyfills. For future reference, I ended up using variables for both the font and the font

How do CSS custom properties cascade?

江枫思渺然 提交于 2019-11-28 07:57:37
问题 Let's say I have following CSS : :root { --color: blue; } div { --color: green; } #alert { --color: red; } * { color: var(--color); } and my markup is : <p>I inherited blue from the root element!</p> <div>I got green set directly on me!</div> <div id="alert"> While I got red set directly on me! <p>I’m red too, because of inheritance!</p> </div> My question is Does the CSS above translate to : body { color: blue; } div { color: green; } #alert{ color: red; } or is there an additional * { color

Is it possible to use CSS Custom Properties in values for the content property?

三世轮回 提交于 2019-11-28 05:49:31
问题 Example: :root { --PrimaryThemeColor: #3acfb6; /* with or without quotes */ } .ColorSwatch:after { content: var(--PrimaryThemeColor); } When this is rendered, the computed CSS is literally that value. content: var(--PrimaryThemeColor); Even if I'm using a post-processor that injects the computed value as a fallback, the value itself isn't a string, so it's invalid for content . .ColorSwatch:after { content: #3acfb6; content: var(--PrimaryThemeColor); } 回答1: The value of the custom property

CSS animate custom properties/variables

扶醉桌前 提交于 2019-11-28 04:57:29
问题 I have been trying to get this to work for a while. The point is that the inner div will have some shape and there will probably more than one (That's why I used the nth-child selector). This inner div is supposed to be shown and then be hidden again both for some set amount of time. the problem is, that I would like to animate all the (later) multiple inner divs in one animation. For this I thought I could use CSS variables, but this does not seem to work. What I am trying to archieve in