This question already has answers here:
Do custom CSS properties use one leading dash or two?
(2 answers)
Closed 6 years ago.
I met this strange CSS code here:
:root {
--color-link: #04b;
--color-link-visited: #551a8b;
--color-link-minor: #669;
--color-black: #000;
--color-grey: #999;
--font-thin: HelveticaNeue-thin,sans-serif-thin;
--font-light: HelveticaNeue-Light,sans-serif-light;
--text-s: 11px;
--text-s-line-s: 1em;
--text-s-line-m: 1em;
--typo-caps: 11px;
--typo-greenurl: 13px;
}
I've never seen such CSS properties names before and can't find information about them. But browser inspectors (checked it in Chrome, Safari and Firefox) say they are valid CSS properties, so it must be a CSS standard.
I tried to add my own property and it is valid either:
:root {
--color-foobar: #000;
}
What do these properties do? What the CSS standard describes it? Where can I find a reference about it?
A double leading dash is used for defining custom properties. For more information, check out this W3C Spec page.
Example from W3C:
:root {
--main-color: #05c;
--accent-color: #056;
}
#foo h1 {
color: var(--main-color);
}
Related
This question already has answers here:
Does the order of classes listed on an item affect the CSS?
(5 answers)
Closed 2 years ago.
I have this code:
<div class="notebox warning accepted">
<h1>This is some random text.</h1>
</div>
and this css
.notebox{
border: 4px solid black;
padding: 10px;
margin: 20px;
}
.notebox.accepted{
border-color: green;
}
.notebox.warning{
border-color: red;
}
If I use it in this order
class="notebox warning accepted"
warning is dominant, but if I use it in this order:
class="notebox accepted warning"
Then warning is dominant, which makes sense.
I want to know why the first example doesn't work like the second, and I know that it has to do with the order that they are placed in the css file but I want to know more details about it, why does the order matter in that case?
CSS has cascading and specificity rules. The order and how specifically you target selectors determines which styles will be applied. The actual order of the CSS classes in your HTML doesn't matter.
https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity
https://css-tricks.com/the-order-of-css-classes-in-html-doesnt-matter/
This question already has answers here:
Rem fallback for ie7-8
(1 answer)
Which fallback is best when using rem as font-size unit in a responsive environement?
(4 answers)
Closed 4 years ago.
Could you explain please, what this code mean
h1{
font-size: 36px !important;
font-size: 3.6rem!important;
}
Or this
body {
background: $backgroundColor;
font-size: 14px;
font-size: 1.4rem;
}
Why is there duplicated font-size properties?
Alright, here’s the full rundown.
rem is a unit that does not work or is significantly buggy in older browsers, notably IE. See the CanIUse entry.
CSS allows you to declare a rule multiple times, with the last one winning. This is often used to feed old or noncompliant browsers a fallback value which a newer or compliant browser will also read but will then overwrite with the last value given.
So:
.example {
font-size: 12px;
font-size: 1.1rem;
background-color: blue;
background-color: red;
}
Any browser will decide the background color is red (not blue), and any up-to-date browser will set the font size at 1.1rem. But a browser that does not understand what “rem” is will discard that rule and keep the prior one (12px).
The duplicated declarations use for fallback in order to support older browsers.
The !important declarations use to override rules and consider not a good practice.
As for your question regarding font-size units - the rem is not supported with legacy browsers.
MDN have very good explanation about HTML and CSS fallback behaviour: https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/HTML_and_CSS
Hope that helps.
This question already has answers here:
Do custom CSS properties use one leading dash or two?
(2 answers)
Closed 6 years ago.
I met this strange CSS code here:
:root {
--color-link: #04b;
--color-link-visited: #551a8b;
--color-link-minor: #669;
--color-black: #000;
--color-grey: #999;
--font-thin: HelveticaNeue-thin,sans-serif-thin;
--font-light: HelveticaNeue-Light,sans-serif-light;
--text-s: 11px;
--text-s-line-s: 1em;
--text-s-line-m: 1em;
--typo-caps: 11px;
--typo-greenurl: 13px;
}
I've never seen such CSS properties names before and can't find information about them. But browser inspectors (checked it in Chrome, Safari and Firefox) say they are valid CSS properties, so it must be a CSS standard.
I tried to add my own property and it is valid either:
:root {
--color-foobar: #000;
}
What do these properties do? What the CSS standard describes it? Where can I find a reference about it?
A double leading dash is used for defining custom properties. For more information, check out this W3C Spec page.
Example from W3C:
:root {
--main-color: #05c;
--accent-color: #056;
}
#foo h1 {
color: var(--main-color);
}
This question already has answers here:
Do custom CSS properties use one leading dash or two?
(2 answers)
Closed 6 years ago.
I met this strange CSS code here:
:root {
--color-link: #04b;
--color-link-visited: #551a8b;
--color-link-minor: #669;
--color-black: #000;
--color-grey: #999;
--font-thin: HelveticaNeue-thin,sans-serif-thin;
--font-light: HelveticaNeue-Light,sans-serif-light;
--text-s: 11px;
--text-s-line-s: 1em;
--text-s-line-m: 1em;
--typo-caps: 11px;
--typo-greenurl: 13px;
}
I've never seen such CSS properties names before and can't find information about them. But browser inspectors (checked it in Chrome, Safari and Firefox) say they are valid CSS properties, so it must be a CSS standard.
I tried to add my own property and it is valid either:
:root {
--color-foobar: #000;
}
What do these properties do? What the CSS standard describes it? Where can I find a reference about it?
A double leading dash is used for defining custom properties. For more information, check out this W3C Spec page.
Example from W3C:
:root {
--main-color: #05c;
--accent-color: #056;
}
#foo h1 {
color: var(--main-color);
}
This question already has answers here:
“text-decoration” and the “:after” pseudo-element, revisited
(11 answers)
Closed 8 years ago.
The goal of my question is to create a code which adds the filetype after a link (so that people know whether they should expect any special files). Now there are options to do this using an image, but I don't really like it and I would prefer to have the file type between square brackets in a different size. My approach is to use the :after pseudoclass in the following way
a[href$='.doc']:after, a[href$='.rtf']:after {
content: " [DOC]";
font-family: Monospace;
font-size: 60%;
font-weight:bolder;
color:red;
position:relative;
top: -0.8em;
}
However, this gets me a very strange problem. The content seems to be in a block which is part of the link. Therefore the link underlining continues after the link under the "[DOC]".
So the question is pretty straightforward: Is there a way to either do this in another way or to make sure that I can control what is under the "[DOC]" separately from what is under the link?
Try adding display: inline-block;
a[href$='.doc']:after, a[href$='.rtf']:after {
content: " [DOC]";
display: inline-block;
font-family: Monospace;
font-size: 60%;
font-weight:bolder;
color:red;
position:relative;
top: -0.8em;
}
not tested in IE but I think IE has trouble with attribute selectors and :after or both.
I hope someone will swoop down and point out a cleaner way, but this works:
Live Demo
HTML:
<span>lol</span>
CSS:
a {
text-decoration: none
}
a span {
text-decoration: underline
}
a[href$='.doc']:after, a[href$='.rtf']:after {
content: " [DOC]";
font-family: Monospace;
font-size: 60%;
font-weight:bolder;
color:red;
position:relative;
top: -0.8em;
}
All: I will probably stick to an image since that seems to be a bit more robust (in terms of supporting browsers). My naive view of the world, that a plain text should always be easier than an image is wrong in this case ;).