Less mixins do not inherit classes - css

I'm new with Less.js, I need to reuse the p.InputTitle like my examples, but it is not working for me :( it is giving me an error. I read more about mixins and some people tell me that I can use 'Extend'. What is that?
Here My code :
.LoginForm {
p.InputTitle {
color: #656565;
font-size: 14px;
font-family: #OpenSans;
font-weight: 600;
}
}
.Membership{
p.InputTitle {
.LoginForm p.InputTitle;
}
}

Use Less extend pseudo class:
.Membership{
p.InputTitle {
&:extend(.LoginForm p.InputTitle);
}
}
This will then produce:
.LoginForm p.InputTitle,
.Membership p.InputTitle {
color: #656565;
font-size: 14px;
font-weight: 600;
}
Your syntax is calling in the form of a mixin call and a mixin name cannot be p.InputTitle.
If you were to change your original LoginForm CSS to the following then this would act as a valid mixin:
.LoginForm {
.InputTitle {
color: #656565;
font-size: 14px;
font-weight: 600;
}
}
You could then write:
.Membership{
p.InputTitle {
.LoginForm .InputTitle;
}
}
However this would then produce double the amount of CSS styles:
.LoginForm .InputTitle {
color: #656565;
font-size: 14px;
font-weight: 600;
}
.Membership p.InputTitle {
color: #656565;
font-size: 14px;
font-weight: 600;
}

Related

Sass duplicate <styles> tag with the same content in the html file (Vue)

I have some sass files in my proyect to define generig sass variables and styles. To use this variables in components, I need configure sass loader in this way:
// vue.config.js
module.exports = {
css: {
loaderOptions: {
sass: {
prependData: `
#import "#/styles/main.sass"
`
}
}
}
};
The main.sass file import all generic sass style sheets. This file contains:
// main.sass
#import "variables"
#import "typo"
With this I can use global sass variables in my vue components and It´s not necessary to import in each components.
Everything words fine but when I see the rendered html file of web app, the style tags are duplicated:
<style type="text/css">#import url(https://fonts.googleapis.com/css2?family=Roboto&display=swap);</style>
<style type="text/css">#import url(https://fonts.googleapis.com/css2?family=Roboto&family=Roboto+Slab&display=swap);</style>
<style type="text/css">
#app {
font-family: "Roboto", sans-serif;
}
#app h1 {
font-family: "Roboto Slab", serif;
font-size: 24px;
line-height: 30px;
}
#app h1 > b {
font-weight: 700;
}
#app strong > h1 {
font-family: "Roboto Slab", serif;
font-size: 24px;
line-height: 38px;
font-weight: 700;
color: #4BA7EE;
}
#app {
text-align: center;
}
#nav {
padding: 30px;
}
</style>
<style type="text/css">#import url(https://fonts.googleapis.com/css2?family=Roboto&display=swap);</style>
<style type="text/css">#import url(https://fonts.googleapis.com/css2?family=Roboto&family=Roboto+Slab&display=swap);</style>
<style type="text/css">
#app[data-v-469af010] {
font-family: "Roboto", sans-serif;
}
#app h1[data-v-469af010] {
font-family: "Roboto Slab", serif;
font-size: 24px;
line-height: 30px;
}
#app h1 > b[data-v-469af010] {
font-weight: 700;
}
#app strong > h1[data-v-469af010] {
font-family: "Roboto Slab", serif;
font-size: 24px;
line-height: 38px;
font-weight: 700;
color: #4BA7EE;
}
h3[data-v-469af010] {
margin: 40px 0 0;
}
ul[data-v-469af010] {
list-style-type: none;
padding: 0;
}
li[data-v-469af010] {
display: inline-block;
margin: 0 10px;
}
a[data-v-469af010] {
color: #42b983;
}
</style>
There is only one difference, the last style seems to be scoped
I don´t know if this is normal or the style sheets is being imported more than one time.
I have tried to comment the sass loader(vue.config.js) and every style tags disappear.

programmatically add custom css design tokens to material-ui components

I'm using material-ui components in my react-redux app. I had created the UI prototype using adobe-xd, which provides an option to export the character styles (design tokens) in the form of a css file:
:root {
/* Colors: */
--text-color: #F8E29F;
--unnamed-color-6c63ff: #6C63FF;
--message-bar-avatar-panel: #3F4851;
--name-text: #A6BCD0;
--eth-subtext-stars: #748A9D;
--navbar-footer-stars-bg: #232323;
--unnamed-color-7b8188: #7B8188;
--bg-drawer: #101010;
/* Font/text values */
--unnamed-font-family-fira-sans: Fira Sans;
--unnamed-font-family-abril-fatface: Abril Fatface;
--unnamed-font-style-light: Light;
--unnamed-font-style-regular: Regular;
--unnamed-font-size-7: 7px;
--unnamed-font-size-8: 8px;
--unnamed-font-size-14: 14px;
--unnamed-font-size-16: 16px;
--unnamed-font-size-24: 24px;
--unnamed-font-size-28: 28px;
--unnamed-font-size-32: 32px;
--unnamed-character-spacing-0: 0px;
--unnamed-character-spacing-0-96: 0.96px;
--unnamed-character-spacing-1-15: 1.15px;
--unnamed-character-spacing-1-31: 1.31px;
--unnamed-line-spacing-10: 10px;
--unnamed-line-spacing-12: 12px;
--unnamed-line-spacing-20: 20px;
--unnamed-line-spacing-24: 24px;
--unnamed-line-spacing-32: 32px;
}
/* Character Styles */
.text-ultra-small-mobile- {
font-family: var(--unnamed-font-family-fira-sans);
font-style: var(--unnamed-font-style-light);
font-size: var(--unnamed-font-size-7);
line-height: var(--unnamed-line-spacing-20);
letter-spacing: var(--unnamed-character-spacing-0);
color: var(--name-text);
}
.text-very-small-dim-mobile- {
font-family: var(--unnamed-font-family-fira-sans);
font-style: var(--unnamed-font-style-light);
font-size: var(--unnamed-font-size-8);
line-height: var(--unnamed-line-spacing-10);
letter-spacing: var(--unnamed-character-spacing-0);
color: var(--eth-subtext-stars);
}
.text-very-small-mobile- {
font-family: var(--unnamed-font-family-fira-sans);
font-style: var(--unnamed-font-style-light);
font-size: var(--unnamed-font-size-8);
line-height: var(--unnamed-line-spacing-12);
letter-spacing: var(--unnamed-character-spacing-0);
color: var(--name-text);
}
.text-small-mobile- {
font-family: var(--unnamed-font-family-fira-sans);
font-style: var(--unnamed-font-style-light);
font-size: var(--unnamed-font-size-14);
line-height: var(--unnamed-line-spacing-20);
letter-spacing: var(--unnamed-character-spacing-0);
color: var(--text-color);
}
.text-mobile- {
font-family: var(--unnamed-font-family-fira-sans);
font-style: var(--unnamed-font-style-light);
font-size: var(--unnamed-font-size-16);
line-height: var(--unnamed-line-spacing-24);
letter-spacing: var(--unnamed-character-spacing-0);
color: var(--text-color);
}
.drawer-menu-items-mobile- {
font-family: var(--unnamed-font-family-fira-sans);
font-style: var(--unnamed-font-style-light);
font-size: var(--unnamed-font-size-16);
line-height: var(--unnamed-line-spacing-24);
letter-spacing: var(--unnamed-character-spacing-0);
color: var(--unnamed-color-7b8188);
}
.text-secondary-dim-mobile- {
font-family: var(--unnamed-font-family-fira-sans);
font-style: var(--unnamed-font-style-light);
font-size: var(--unnamed-font-size-16);
line-height: var(--unnamed-line-spacing-24);
letter-spacing: var(--unnamed-character-spacing-0);
color: var(--eth-subtext-stars);
}
.text-secondary-mobile- {
font-family: var(--unnamed-font-family-fira-sans);
font-style: var(--unnamed-font-style-light);
font-size: var(--unnamed-font-size-16);
line-height: var(--unnamed-line-spacing-24);
letter-spacing: var(--unnamed-character-spacing-0);
color: var(--name-text);
}
.text-secondary-bold-mobile- {
font-family: var(--unnamed-font-family-fira-sans);
font-style: var(--unnamed-font-style-regular);
font-size: var(--unnamed-font-size-16);
line-height: var(--unnamed-line-spacing-24);
letter-spacing: var(--unnamed-character-spacing-0);
color: var(--name-text);
}
.heading-mobile- {
font-family: var(--unnamed-font-family-abril-fatface);
font-style: var(--unnamed-font-style-regular);
font-size: var(--unnamed-font-size-24);
line-height: var(--unnamed-line-spacing-32);
letter-spacing: var(--unnamed-character-spacing-0-96);
color: var(--text-color);
}
.title-mobile- {
font-family: var(--unnamed-font-family-abril-fatface);
font-style: var(--unnamed-font-style-regular);
font-size: var(--unnamed-font-size-28);
line-height: var(--unnamed-line-spacing-32);
letter-spacing: var(--unnamed-character-spacing-1-15);
color: var(--text-color);
}
.title-web- {
font-family: var(--unnamed-font-family-abril-fatface);
font-style: var(--unnamed-font-style-regular);
font-size: var(--unnamed-font-size-32);
line-height: var(--unnamed-line-spacing-32);
letter-spacing: var(--unnamed-character-spacing-1-31);
color: var(--text-color);
}
is there some way that I can programmatically import this custom CSS values for character-styles (and color styles) to reflect in all my material-ui components?, like design tokens injection of sorts? everytime i make changes to the adobe-xd prototypes and save a new css, it should import the values from that css and reflect in the material-ui components. You can also suggest if there is a better way to implement design tokens from prototype (adobe-xd) to codebase (react UI frameworks)
use Css Import on your File and Put Css From Adobe Xd Share tab to Advanced Export plugin to Variable.Css

#for loop in a mixin in precss or sass

I have this great for loop in my precss style sheet. I would like to convert it to a mixin where i can pass the start values for $size (font-size) and $spacing(letter-spacing) for different media queries. I cannot get the variables to increment as i progress through the loop when i call it from a mixin. It works fine from the stylesheet
/*--adds .4 rem to each heading fz and character spacing 1-6---*/
$size: 1.8rem;
$spacing: 7px;
#for $i from 6 through 1 {
h$i {
font-size: resolve($size);
letter-spacing: resolve($spacing);
#extend %heading;
}
$size: $size + .4rem;
$spacing: $spacing * 1.2;
}
Your current code is close to working as a mixin when wrapped in a #mixin declaration in SCSS. The only tweak needed is outputting the $i in the selector using the #{$variable}
SCSS input:
%heading{
/* heading properties */
color: #999;
font-family: sans-serif;
}
#mixin headingSize($size: 1.8rem, $spacing: 7px){
#for $i from 6 through 1{
h#{$i}{
#extend %heading;
font-size: $size;
letter-spacing: $spacing;
}
$size: $size + .4rem;
$spacing: $spacing * 1.2;
}
}
#include headingSize($size: 2rem, $spacing: 10px);
This example uses your original $size and $spacing variables as default parameters in the mixin.
Here's an example JSFiddle in action.
CSS output:
h6, h5, h4, h3, h2, h1 {
/* heading properties */
color: #999;
font-family: sans-serif;
}
h6 {
font-size: 2rem;
letter-spacing: 10px;
}
h5 {
font-size: 2.4rem;
letter-spacing: 12px;
}
h4 {
font-size: 2.8rem;
letter-spacing: 14.4px;
}
h3 {
font-size: 3.2rem;
letter-spacing: 17.28px;
}
h2 {
font-size: 3.6rem;
letter-spacing: 20.736px;
}
h1 {
font-size: 4rem;
letter-spacing: 24.8832px;
}

Sass: Extending nested selectors

(I think I should mention this, I've only recently started using Sass/SCSS)
http://jsfiddle.net/DriftingSteps/t6kLncfm/
You can see how <strong> is inheriting the properties of the global <a> as well as the properties from nested <a> tag.
a {
color: #09f;
text-decoration: none;
&:hover {
text-decoration: underline;
opacity: 0.6;
}
}
ul {
font-size: 0.85em;
a {
font-family: Georgia, Times, serif;
font-style: italic;
color: #0a3;
}
strong {
#extend a;
}
}
I have been going through http://sass-lang.com/ and I know I'm missing something.
What am I doing wrong? Is there a way to inherit properties from the nested <a> only, without the use of classes on either ul a and ul strong? Or is there a better way to do this?
You could use an extend-only selector (%), and extend both ul a and ul strong from that:
a {
color: #09f;
text-decoration: none;
&:hover {
text-decoration: underline;
opacity: 0.6;
}
}
ul {
font-size: 0.85em;
a {
#extend %a;
}
strong {
#extend %a;
}
}
%a {
font-family: Georgia, Times, serif;
font-style: italic;
color: #0a3;
}
You don't have to use that class and you don't have to apply it to your HTML, you can just define it and refer to it when inheriting:
a, .a {
font-family: Georgia, Times, serif;
font-style: italic;
color: #0a3;
}
strong {
#extend .a;
}
Demonstration
And of course, in this case you don't really need extend:
a, strong {
font-family: Georgia, Times, serif;
font-style: italic;
color: #0a3;
}
strong {
// other stuff
}
It seems to me that the real use case of extend isn't deep localized selectors defined together, but rather the extension of a selector defined elsewhere.

CSS link to act as button but inheriting behavior

I have link CSS define as:
A
{
color: #315393; font-family: verdana; font-weight: 500; text-decoration:underline; font-size: 10px;
}
A:Hover
{
color: #999999; font-family: verdana; font-weight: 500; text-decoration:none; font-size: 10px;
}
However, there are a couple cases where I want a link to act like a button and for that I use bootstrap and give them the class of "btn btn-primary", but since they are still links it seems they are still using the above CSS. How can I exclude the link behavior CSS from these and is there a way to do it in-line to the link?
You can use :not pseudo-class to exclude certain elements from the matched selector:
a:not(.btn.btn-primary) {
color: #315393;
font-family: verdana;
font-weight: 500;
text-decoration:underline;
font-size: 10px;
}
a:not(.btn.btn-primary):hover {
color: #315393;
font-family: verdana;
font-weight: 500;
text-decoration:underline;
font-size: 10px;
}

Resources