Why my scss doesn't take the universal selector? - css

I'm learning Sass and I choose to try with Scss syntax, but there is an error when I try to complile the scss code to css.
Here is the command line's error:
> starter#1.0.0 compile:sass C:\Users\xxx
> node-sass sass/main.scss css/style.css
{
"status": 1,
"file": "C:/Users/xxx/sass/main.scss",
"line": 14,
"column": 1,
"message": "Invalid CSS after \"*\": expected expression (e.g. 1px, bold), was \",\"",
"formatted": "Error: Invalid CSS after \"*\": expected expression (e.g. 1px, bold), was \",\"\n
on line 14 of sass/main.scss\n>> *,\r\n ^\n"
}
This is my Scss file:
*,
*::after,
*::before {
margin: 0;
padding: 0;
box-sizing: inherit;
}
html{
font-size: 62.5%;
}
body{
font-family: "Lato", sans-serif;
font-weight: 400;
font-size: 1.6rem;
line-height: 1,7;
color: #777;
padding: 3rem;
box-sizing: border-box;
}
And I'm running it through the Package.json:
{
"name": "starter",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"compile:sass": "node-sass sass/main.scss css/style.css"
},
"author": "",
"license": "ISC",
"devDependencies": {
"node-sass": "^4.14.1"
}
}
For some reason it says that the universal selector is not Css code, and I tried by comenting that selector out but then it says the same for the html selector.
-------UPDATE-------
The error stopped once I used the 7-1 css architecture. The universal selector became acepted when I put it in another file, so the problem was fixed but I don't know why.

Related

SCSS : Why is this code not compiled in extention "Dart JS sass" at first time. After quit and restart Visual Stadio Code,it can naturaly compiled

SCSS : Why is this code not compiled in extention "Dart JS sass" at first time.Code was saved and compile with watch.But always it can't be compiled.
After quit and restart Visual Stadio Code,it can be naturaly compiled.
I don't know why it nessesory to restart Visual Stadio Code.
This is scss code.
#use "bases" as m;
#top {
.header-top-left {
h1 {
display: inline-block;
padding-right: 20px;
font-size: 10px;
#include m.tab {
font-size: 9px;
height: 24px;
line-height: 24px;
}
#include m.sp {
padding: 0;
}
}
}
This is "bases" as m.'s code.
#mixin tab{ #media screen and (max-width: ($tab))
{
#content;
}
}
This is css error code.
Error: Invalid CSS after " #include m": expected "}", was ".tab {"
on line 12 of /Users/***/Desktop/***/***/***/scss/top.scss
7: .header-top-left {
8: h1 {
9: display: inline-block;
10: padding-right: 20px;
11: font-size: 10px;
12: #include m.tab {
13: font-size: 9px;
14: height: 24px;
15: line-height: 24px;
16: }
17: #include m.sp {
Backtrace:
/Users/***/Desktop/***/***/***/scss/top.scss:12
This is package.json's code.
{
"name": "project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"sass": "sass scss/:css/ --no-source-map --watch"
},
"author": "***",
"license": "ISC",
"devDependencies": {
"sass": "^1.49.11"
}
}
This is setting.json's code.
{
"dartsass.targetDirectory": "css",
"dartsass.sassBinPath": "/Users/***/node_modules/sass/sass.js",
"dartsass.disableCompileOnSave": false
}

Unable to match font weights with google fonts and react styled components

I'm trying the following style below. The issue is the actual result font-weight is no where close to the mock-up. How can I ensure I get the right style?
https://fonts.google.com/specimenTab?standard-styles#standard-styles
const LogoH1 = styled.span`
text-transform: uppercase;
font-family: 'Montserrat';
font-size: 50px;
font-weight: 900;
letter-spacing: -5px;
`
Design Tool (Adobe XD)
Result
I'm using Gatsby to connect the fonts:
plugins: [
{
resolve: `gatsby-plugin-google-fonts`,
options: {
fonts: [
`Montserrat`,
],
}
}
],
plugins: [
{
resolve: `gatsby-plugin-google-fonts`,
options: {
fonts: [
`Montserrat\:400,500,600,700,800,900`,
],
}
}],

React: Production build looks different from development build

I have a React/Django app that's behaving differently when built for production that it does when run on the development server. The development version is how I want it to look.
There are a number of issues with the CSS. Text is a different font, and a some Bootstrap/Reactstrap features are ignored. See example screenshots below.
I think the issue has to do with the order in which css files are processed by the dev server, versus how Django serves the built app, by collecting the files in the /build dir created by the build script into the Django /staticfiles dir. I'm mystified how this would selectively apply classes to the same component, however. (See below - the offset of the jumbotron text is different, while the column size is the same)
Here's a screenshot of the home page in the production build, either served locally by Django or remotely on Heroku. (npm run build or npm run build-local - see package.json file below)
And here is how it looks on the local dev server: (npm run start)
In particular, the offset-md-5 class is ignored on the production build, while the rest of the classes aren't, col-md-5 for example applies in both versions.
Here's the relevant component:
const Photojumbo = () => {
return(
<Container className="jumbo-text ">
<Jumbotron className="" style={{ backgroundImage: "url(/static/photosquat-cropped.jpg)", backgroundSize: 'cover' }}>
<Col className="header header-text col-md-5 offset-md-6" >
<h3>ytterblog</h3>
<p>A blog app and portfolio project by Gabriel Ytterberg</p>
</Col>
</Jumbotron>
</Container>
)
}
Here's the part of my package.json with the build scripts and dependencies. Note that I added the build-local script to emulate how it would look deployed to Heroku, since the deploy process takes so long. The build-local and Heroku build version are identical as far as I can tell.
"dependencies": {
"#testing-library/jest-dom": "^5.11.5",
"#testing-library/react": "^11.1.0",
"#testing-library/user-event": "^12.1.10",
"axios": "^0.21.0",
"bootstrap": "^4.5.3",
"bootstrap-social": "^5.1.1",
"express": "^4.17.1",
"font-awesome": "^4.7.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-fontawesome": "^1.7.1",
"react-redux": "^7.2.2",
"react-redux-form": "^1.16.14",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.0",
"react-transition-group": "^4.4.1",
"reactstrap": "^8.7.1",
"redux": "^4.0.5",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "PUBLIC_URL=http://localhost:3000/ react-scripts start",
"build": "PUBLIC_URL=https://ytterblog.herokuapp.com/ react-scripts build",
"build-local": "PUBLIC_URL=http://localhost:8000/ react-scripts build && python manage.py collectstatic --noinput",
"postbuild": "python manage.py collectstatic --noinput",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
Here's my App.css, which is the only css file I'm using:
height: 40vmin;
pointer-events: none;
}
#media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
#keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
.jumbotron {
position:relative;
left: 0px;
top: 0px;
right: 0px;
bottom: 0px;
margin: 0 auto;
background: none;
color:floralwhite;
}
.navbar-dark {
background-color: #142f87;
}
.header{
background-color: #1a3db0;
margin:0px auto;
padding: 20px 0px 20px 0px;
}
.header-text{
color: #dbdbdb;
text-align: center;
}
.footer{
background-color: #1a3db0;
margin-top: 50px;
padding: 20px 0px 20px 0px;
position: relative;
}
.footer-text{
color: #dbdbdb;
text-align: center;
}
.avatar{
height: 100;
width: 100;
margin: 20px;
}
.postcard{
margin: 50px 0px 50px 0px;
}
dl {
display: grid;
grid-template-columns: max-content auto;
column-gap: 20px;
}
dt {
grid-column-start: 1;
}
dd {
grid-column-start: 2;
}
.card {
padding-right: 0!important;
padding-left: 0!important;
}
What am I missing?!?!
It could be race condition. I had an issue where in production, the setState getting called twice, and somehow it run in parallel. The result rendered was half 1st state, and the other half was 2nd state.
I don't remember how did I solve it. Though, you try check if a setState is busy.
Use the developer tools on the browser to see if any bootstrap CDNs or other libraries are not loading properly if any of them are being blocked or ignored somehow it will probably be displayed on the console of the developer tools, that is what I would do.

!important CSS Attribute [duplicate]

Can anyone explain this to me. I'm trying to inject a CSS file onto a webpage using the content_script with Google extensions, but my css file never gets added to the webpage. Can someone tell me what I'm doing wrong and help me fix it? thanks
Manifest:
{
"name": "Extension",
"version": "0",
"description": "",
"permissions": ["tabs", "http://*/*", "https://*/*", "file:///*/*"],
"content_scripts": [
{
"matches": [ "http://*/*", "https://*/*", "file:///*/*"],
"css": ["myStyles.css"],
"js": ["myScript.js"],
"all_frames": true
}
]
}
myStyles.css
#test {
margin: 0 10px;
background: #fff;
padding: 3px;
color: #000;
}
The style sheet is actually injected, but not applied, because other styles override the rules. To get the rules to work, you have some options:
Increase the specificity of your CSS rules.
Suffix every rule with !important:
#test {
margin: 0 10px !important;
background: #fff !important;
padding: 3px !important;
color: #000 !important;
}
Inject the CSS via a content script:
myScript.js:
var style = document.createElement('link');
style.rel = 'stylesheet';
style.type = 'text/css';
style.href = chrome.extension.getURL('myStyles.css');
(document.head||document.documentElement).appendChild(style);
manifest.json
{
"name": "Extension",
"version": "0",
"description": "",
"manifest_version": 2,
"permissions": ["tabs", "http://*/*", "https://*/*", "file:///*/*"],
"content_scripts": [
{
"matches": [ "http://*/*", "https://*/*", "file:///*/*"],
"js": ["myScript.js"],
"all_frames": true
}
],
"web_accessible_resources": ["myStyles.css"]
}
The last key, web_accessible_resources is necessary when manifest version 2 is active, so that the CSS file can be read from a non-extension page.
If you want to target a specific website do:
"matches": ["https://*.google.com/*"]
That //* before .google is the real trick for me as using www doesn't works.

How can I get grunt-autoprefixer to prefix uncompiled LESS files?

I'm working with LESS and I'd like to run grunt-autoprefixer on my LESS markup WITHOUT compiling LESS, because my LESS is compiled on my CMS automatically.
Is this possible?
Here's my Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
concat: {
sqs_template: {
src: ['js/one.js', 'js/two.js'],
dest: 'sqs_template/scripts/app.js',
},
},
autoprefixer: {
options: {
remove: true,
},
multiple_files: {
expand: true,
flatten: true,
src: 'css/*.less',
dest: 'sqs_template/css/',
},
},
watch: {
js: {
files: ['js/**/*.js'],
tasks: ['concat'],
},
css: {
files: ['css/**/*.less'],
tasks: ['autoprefixer'],
},
},
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.loadNpmTasks('grunt-contrib-watch');
};
Here's an example of the LESS I'm trying to prefix:
//------------------------------------*\
// SOME CSS
//------------------------------------*/
// Variables
#site-width: 960px;
#color: #333333;
// Mixins
.some-font {
font-family: sans-serif;
font-size: 1.5rem;
font-weight: bold;
}
.some-container {
display: flex;
max-width: #site-width;
margin: 0 auto;
.some-container-inner {
p {
.some-font;
color: #color;
}
}
}
I would want grunt-autoprefixer to do nothing but prefix my LESS, and put it into the sqs_template folder. Right now, grunt-autoprefixer errors because it doesn't seem to recognize the variables or mixins.
Is this possible?
Thanks!
Instead of autoprefixing, you could use mixins to prefix the needed values yourself. There's LESS-Prefix library that contains mixins for the usual suspects.
As a simple example, if you are using LESS-Prefix (or have a similar mixin yourself), you can just include the mixin file and type the CSS-properties prepended by a .
div {
.box-shadow(0px 0px 10px rgba(255,0,0,.5));
}
which passes the values through this mixin:
.box-shadow(#args) {
-webkit-box-shadow: #args;
box-shadow: #args;
}
and you'll end up with this:
div {
-webkit-box-shadow: 0px 0px 10px rgba(255,0,0,.5);
box-shadow: 0px 0px 10px rgba(255,0,0,.5);
}

Resources