What Does This Error in SASS Mean? "Illegal Nesting: Only Properties May Be Nested Beneath Properties."

What does this error in Sass mean? Illegal nesting: Only properties may be nested beneath properties.

You're missing a semicolon:

.navigation {
padding: 0;
margin: 0;
background: #333;
position: fixed;
top: 0;
z-index: 999;
width: 100%; <=== right here

Sass gulp crashes - SCSS Error : Illegal nesting: Only properties maybe nested beneath properties

The lessons I learned that I hope will save someone else a lot of time are:

  1. When sass-gulp crashes it is more than likely a sass/scss error rather than a gulp error.I didn't know this because most syntax errors get piped to the console by error handling in the gulp file, however it turns out if your error is a little more serious it can still crash gulp.
  2. When you get an error message from a scss or sass file the error might not actually be in that file. I ended up randomly disabling all files to eventually find the offending file because the error message gave the wrong file name.

I found this out after sass-gulp started working again when I commented out lines 10 and 37 in _media.scss which are the '@content ' directives even though there weren't actually any errors in these lines or even in the _media.scss file:

What is @content directive ?

These directives call my code from other sass files. It was my own files else where that were breaking the mixin and making gulp crash when they were called by @content

If you look in the .find-drawer class from the offending file you will see that all the media queries are nested inside the margin-bottom: -33px rule

.find-drawer
margin-bottom: -33px
@include media(max-width $tablet-size)
margin-bottom: 0
@include media(max-width $small-screen)
margin-bottom: 0
@include media(max-width $mobile-screen)
margin-bottom: 0

This must have generated a really crazy media queries because it was fed into a loop in _media.scss

I just shifted the media queries a couple of spaces to the left so that they are now nested inside .find-drawer class

.find-drawer
margin-bottom: -33px
@include media(max-width $tablet-size)
margin-bottom: 0
@include media(max-width $small-screen)
margin-bottom: 0
@include media(max-width $mobile-screen)
margin-bottom: 0

Phew! What a relief !

Strange gulp crashes caused by SASS errors

Run this command and reset the universe

npm install gulp-sass

or trace the error

sass --trace --watch input.scss:output.css

Nested mixins or functions in SASS

yeah you already doing it right. You can call first mixin in second one. check this pen http://codepen.io/crazyrohila/pen/mvqHo

Including another class in SCSS

Looks like @mixin and @include are not needed for a simple case like this.

One can just do:

.myclass {
font-weight: bold;
font-size: 90px;
}

.myotherclass {
@extend .myclass;
color: #000000;
}

How to create new breakpoints in bootstrap 4 using CDN?

I'm very surprised that there was no developer able to answer my question! Even on the github no one dared to think about it!

In fact, everything turned out to be very simple!

Yes, using the CDN we get the compiled css file. Styles in the bootstrap are written using sass. Moreover, the styles are written separation and modular. So it means that I do not need to load the entire bootstrap to my server. I want to deliver cached version of Bootstrap’s compiled CSS and I only need to add my breakpoints. Fortunately, there is a specific bootstrap file which is responsible for the Grid. It is bootstrap-grid.scss:

/*!
* Bootstrap Grid v4.0.0 (https://getbootstrap.com)
* Copyright 2011-2018 The Bootstrap Authors
* Copyright 2011-2018 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/

@at-root {
@-ms-viewport { width: device-width; } // stylelint-disable-line at-rule-no-vendor-prefix
}

html {
box-sizing: border-box;
-ms-overflow-style: scrollbar;
}

*,
*::before,
*::after {
box-sizing: inherit;
}

@import "functions";
@import "variables";

@import "mixins/breakpoints";
@import "mixins/grid-framework";
@import "mixins/grid";

@import "grid";
@import "utilities/display";
@import "utilities/flex";

Now I just need to add sequentially the code from the files above adding my breakpoints. Add non-Grid code not necessary. For example, the code responsible for the color. Here is my mcve at codepen.

Why is this SCSS selector not working

& translates into existing selector at this exact point. Which means that this

.holder {
&:nth-child(n+2):nth-child(-n+3) {
...some-rule...
&__title {
...other-rule...
}
}
}

translates into this CSS:

.holder:nth-child(n+2):nth-child(-n+3) {
...some-rule...
}
.holder:nth-child(n+2):nth-child(-n+3)__title {
...other-rule...
}

If you're really keen on doing it properly, you should put .holder inside a variable, which doesn't break BEM (you're able to change it from only one place):

$name: '.holder';
#{$name} {
&:nth-child(n+2):nth-child(-n+3) {
...some-rule...
#{$name}__title {
...other-rule...
}
}

which translates into this:

.holder:nth-child(n+2):nth-child(-n+3) {
...some-rule...
}
.holder:nth-child(n+2):nth-child .holder__title {
...other-rule...
}

Implementing the factory design pattern using metaclasses

I'd love to hear people's comments on this, but I think this is an example of what you want to do

class FactoryMetaclassObject(type):
def __init__(cls, name, bases, attrs):
"""__init__ will happen when the metaclass is constructed:
the class object itself (not the instance of the class)"""
pass

def __call__(*args, **kw):
"""
__call__ will happen when an instance of the class (NOT metaclass)
is instantiated. For example, We can add instance methods here and they will
be added to the instance of our class and NOT as a class method
(aka: a method applied to our instance of object).

Or, if this metaclass is used as a factory, we can return a whole different
classes' instance

"""
return "hello world!"

class FactorWorker(object):
__metaclass__ = FactoryMetaclassObject

f = FactorWorker()
print f.__class__

The result you will see is: type 'str'

Nested classes not working in CSS Modules with webpack

Sample ImageHow are you importing the css file ?

You can follow the below way to import too,

In your component,

import ‘styles.css’

In HTML element,

<div className='carousel'>
<div className='test'></div>
</div>

In webpack config,

{
test: /\.css$/,
use: [ 'style-loader', 'css-loader' ]
}

ruby regular expression and extraction from string

That string looks like it's actually not a string but a URI. So, let's treat it as one:

require 'uri'
uri = URI.parse(str)

Now, extracting the path component of the URI is a piece of cake:

path = uri.path

Now we have already greatly limited the amount of stuff that can go wrong with our own parsing. The only part of the URI we still have to deal with, is the path component.

A Regexp that matches the part you are interested in looks like this:

%r|/to/\w+/(.*/)t$|i

If we put all of that together, we end up with something like this:

require 'uri'

def URI.extract(uri)
return parse(uri).path[%r|/to/\w+/(.*/)t$|i, 1]
end

require 'test/unit'
class TestUriExtract < Test::Unit::TestCase
def test_that_the_path_gets_extracted_correctly
uri = 'http://linkto.com/to/1pyTZl/somesite.com/2009/10/monit-on-ubuntu/t'
path = 'somesite.com/2009/10/monit-on-ubuntu/'
assert_equal path, URI.extract(uri)
end
end


Related Topics



Leave a reply



Submit