Less global variable and mixin usage in media-queries - less

I've got a problem when using global varibale in a mixin which is used in #media-query.
Point is in different #media-query the variable is rewrited. So I would like the mixin to use updated value but it doesnt seem to do it.
Here's whats bugging me:
#base-font-size: 18px;
#modifier: 7;
// font size for elements that are not headings
// if I pass "clean" as second arg then the line-height will be same as font size
// dont focus on it - #modifier is the problem
.font(#size, #line-height) when (#line-height = clean) {
font-size: #size;
line-height: #size;
}
.font(#size, #line-height: true) when not (#line-height = clean) {
font-size: #size;
line-height: unit((#size + #modifier), px);
}
body {
.font(#base-font-size);
}
#media (max-width: 800px) {
#base-font-size: 18px;
#modifier: 5;
body {
.font(#base-font-size);
color: red;
}
}
It compiles into:
body {
font-size: 18px;
line-height: 25px;
}
#media (max-width: 800px) {
body {
font-size: 18px;
line-height: 25px;
color: red;
}
}
The #modifier value in #media has changed.
If I would like to use it in #media like this: line-height: #modifier+#base-font-size then the new value would be used and everything is ok.
But when I want to use this new value in a mixin and use this mixin in #media - then this mixin is using old value(7) not the new one(5).
Could anyone please advice where I made my mistake and if's a less bug (1.3.3) how can change my mixin to avoid it?

I've solved this.
I needed to define one more var: #media and vary my mixins so that they will or wont be used in particular cases.
#media: desktop;
#base-font-size: 10px;
#mod-desktop: 10;
#mod-mobile: 1px;
.font(#size, #line-height) when (#line-height = clean) and (#media = desktop) {
font-size: #size;
line-height: #size;
}
.font(#size, #line-height: true) when not (#line-height = clean) and (#media = desktop) {
#mod: #mod-desktop;
font-size: #size;
line-height: unit((#size + #mod-desktop), px);
}
.font(#size, #line-height) when (#line-height = clean) and (#media = mobile) {
font-size: #size;
line-height: #size;
}
.font(#size, #line-height: true) when not (#line-height = clean) and (#media = mobile) {
#mod: #mod-mobile;
font-size: #size;
line-height: unit((#size + #mod-mobile), px);
}
body {
.font(#base-font-size); // this will use font-size from top of the file
}
#media (max-width: 800px) {
#media: mobile;
#base-font-size: 5px;
body {
// this will use the font-size from #media scope and mixin for mobile will be called
.font(#base-font-size);
}
}

Related

How can i change variable value when i use media queries and scss

I have same font-size variables in my site.
I want to change value of this variables when I use media queries in scss... How can i do it...
Below way doesn't exist...
#media screen and (min-width:1000px){
$font-sm: 13px;
$font-default: 15px;
$font-md: 18px;
}
#media screen and (max-width:999px){
$font-sm: 10px;
$font-default: 12px;
$font-md: 14px;
}
Use custom properties instead.
#media screen and (min-width: 400px) {
:root {
--font-sm: 13px;
--font-default: 15px;
--font-md: 18px;
}
}
#media screen and (max-width: 800px) {
:root {
--font-sm: 10px;
--font-default: 12px;
--font-md: 14px;
}
}
body {
font-size: var(--font-default);
}

How to add a top alert banner on Docusaurus 1.x?

I want to show some global message on my Docusaurus site. Something like:
https://codesandbox.io/s/duudl
https://next.ant.design/components/alert/
Is this possible?
You will have to inject the DOM via scripts. An example is React Native website where they injected feedback banners at the bottom of the page - https://facebook.github.io/react-native/docs/getting-started
Look at their repo and the script they used.
Update: you can now add it to the docusaurus.config.js file:
themeConfig:
/** #type {import('#docusaurus/preset-classic').ThemeConfig} */
({
announcementBar: {
id: 'support_ukraine',
content:
'Support Ukraine πŸ‡ΊπŸ‡¦ <a target="_blank" rel="noopener noreferrer" href="https://opensource.facebook.com/support-ukraine"> Help Provide Humanitarian Aid to Ukraine</a>.',
backgroundColor: '#20232a',
textColor: '#fff',
isCloseable: false,
},
...
You can style it with these CSS selectors in src/css/customTheme.scss:
/* Announcement banner */
:root {
--docusaurus-announcement-bar-height: auto !important;
}
div[class^="announcementBar"][role="banner"] {
border-bottom-color: var(--deepdark);
button.close {
svg {
fill: white;
}
}
}
div[class^="announcementBarContent"] {
line-height: 40px;
font-size: 20px;
font-weight: bold;
padding: 8px 30px;
a {
text-decoration: underline;
display: inline-block;
color: var(--brand) !important;
&:hover {
color: var(--ifm-color-primary) !important;
}
}
}
#media only screen and (max-width: 768px) {
.announcement {
font-size: 18px;
}
}
#media only screen and (max-width: 500px) {
.announcement {
font-size: 15px;
line-height: 22px;
padding: 6px 30px;
}
}

Media query fails for only one property

I am unable to change padding for one element on mobile devices. The queries are working for several properties, but padding will not work (neither will line height if I try to use that). Basic styling in custom css is:
#topright {
font-size: 20px;
letter-spacing: 4px;
color: rgba(255,255,255,1.0);
padding-top: 8px !important;
padding-bottom: 8px !important;
font-weight: 200;
}
Media query for phone is
/* Custom, iPhone Retina */
#media only screen and (min-width : 320px) {
.header-2 .logo {
width: 250px;
}
.footer-widget ul li {
width: 100%;
}
.footer-widget ul {
padding-left: 0;
padding-right: 0;
}
div.vc_column-inner vc_custom_1476556729591 {
padding-left: 0;
padding-right: 0;
}
.footer-widget .textwidget p {
text-align: center;
}
#topright {
padding-top: 1px;
padding-bottom: 1px
}
}
The smaller padding number will not be applied. If I remove !important from main css, then the phone query gets applied to all devices. It's weird because all the other properties for the phone query are working fine.
From this helpful page on media queries, min-width: 320px means:
"If [device width] is greater than or equal to 320px, then do {...}"
In other words, the media query you think you created to target only iPhone will actually be firing for all devices which have a width of 320px or greater. Instead, I think you intended to use max-width
So use this CSS:
/* Custom, iPhone Retina */
#media only screen and (max-width : 320px) {
.header-2 .logo {
width: 250px;
}
...
#topright {
padding-top: 1px;
padding-bottom: 1px
}
}
And you should also remove the !important directives from your main.css file.

Less: class then node type

I have two <p> and one <button> that extend a certain class named test. I want to know if it is possible to add certain style rules to .test and then specific rules for the element type?
I thought of something like this:
.test {
font-weight: bold;
color: blue;
&p {
font-size: 26px;
}
&button {
font-size: 20px;
}
}
I know it is impossible to write it like that. This example is only for a concept example.
I've read the documentation and alas i found nothing...
Any idea or is this just impossible to achieve?
If I understand correctly you should use :extend:
LESS:
.test {
font-weight: bold;
color: blue;
}
p:extend(.test) {
font-size: 26px;
}
button:extend(.test){
font-size: 20px;
}
Output:
.test, p, button {
font-weight: bold;
color: blue;
}
p {
font-size: 26px;
}
button {
font-size: 20px;
}

What is wrong with these SCSS media queries [duplicate]

This question already has answers here:
Using Sass Variables with CSS3 Media Queries
(8 answers)
Closed 7 years ago.
I am using the official Sass port of Twitter Bootstrap 3.3.3.
What I am trying to do is shrink the height of the navbar when the window is resized. Below is my media queries, however they don't work as I expect them to.
$navbar-height: 60px !default;
body {
padding-top: 70px !important;
}
#media(min-width: 768px) {
$navbar-height: 70px;
body {
padding-top: 80px !important;
}
}
#media(min-width: 992px) {
$navbar-height: 80px;
body {
padding-top: 90px !important;
}
}
#media(min-width: 1200px) {
$navbar-height: 90px;
body {
padding-top: 100px !important;
}
}
To make it work modify the element inside the #media query not the variable. So for example...
$navbar-height: 60px !default;
body {
padding-top: 70px !important;
}
#media(min-width: 768px) {
.nav-bar: $navbar-height + 10px;
body {
padding-top: 80px !important;
}
}
#media(min-width: 992px) {
.nav-bar: $navbar-height + 20px;
body {
padding-top: 90px !important;
}
}
#media(min-width: 1200px) {
.nav-bar: $navbar-height + 30px;
body {
padding-top: 100px !important;
}
}