Please have a look at Stackblitz or the code below
Having a problem where variables from :root are not set to elements. But when I rename :root => .component. It works as expected. The box is shown.
Why :root variables are not set? Are not they are global or It is specificity problem?
Thanks in advance.
SCSS:
:host {
display: block;
}
:root {
--profile-picture-size-w: 9rem;
--profile-picture-size-h: 9rem;
--profile-picture-border: 1px solid #1e96a9;
--profile-box-backgound-size: cover;
--profile-box-p: 20px 0;
--article-dateInfo: 3px;
}
.component{
height: 500px;
background: lightgray;
#main_content {
.scrollbarContent{
article#profile {
.profileBox {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: var(--profile-box-p);
.profilePicture {
position: relative;
width: var(--profile-picture-size-w);
height: var(--profile-picture-size-h);
background: cyan;
}
}
}
}
}
}
@media all and (min-width: 768px){
:root {
--profile-picture-size-w: 5.5rem;
--profile-picture-size-h: 5.5rem;
--profile-picture-border: 5px solid #1e96a9;
--profile-box-backgound-size: 100% 38%;
--profile-box-p: 20px 0 0 0;
--article-date-info: 0;
}
}
Html:
<div class="component">
<perfect-scrollbar id="main_content">
<div class="scrollbarContent">
<article id="profile">
<div class="profileBox">
<div class="profilePicture">
</div>
</div>
</article>
</div>
</perfect-scrollbar>
</div>
compiled to css output :
:host {
display: block;
height: auto;
margin-left: auto;
margin-top: 6px; }
:root {
--profile-picture-size-w: 9rem;
--profile-picture-size-h: 9rem;
--profile-picture-border: 1px solid #1e96a9;
--profile-box-backgound-size: cover;
--profile-box-p: 20px 0;
--article-dateInfo: 3px; }
.component {
height: calc(100%); }
.component #main_content .scrollbarContent article#profile .profileBox {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: var(--profile-box-p); }
.component #main_content .scrollbarContent article#profile .profileBox .profilePicture {
position: relative;
width: var(--profile-picture-size-w);
height: var(--profile-picture-size-h);
margin-top: 14px;
background: cyan; }
@media all and (min-width: 768px) {
:root {
--profile-picture-size-w: 5.5rem;
--profile-picture-size-h: 5.5rem;
--profile-picture-border: 5px solid #1e96a9;
--profile-box-backgound-size: 100% 38%;
--profile-box-p: 20px 0 0 0;
--article-date-info: 0; }
:host {
height: 77vh; } }
Node-sass package is used to compile scss to css.
SCSS and CSS4 variables behave different.
SCSS variables format:
$color: red;
.classRed{
color: $color;
}
SCSS will compile to CSS this way:
.classRed{
color: red;
}
CSS4 variables format:
:root{
--color: red;
}
.classRed{
color: var(--color);
}
CSS won't compile like SCSS since it is already CSS (it's using the variables CSS4 feature).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With