Having trouble getting SCSS to function properly? (Updated Code)

Transitioning from CSS to SCSS is my current project. I decided to make the switch because of SCSS's nesting capabilities, which I find more convenient for coding. However, I'm facing some challenges getting it to work properly. In my regular CSS, I used the > sign to target specific classes. I assumed that this syntax might not be necessary in SCSS.

Here are snippets of my original CSS code:

/*** External CSS ***/
@import "normalize.css";

/*** Page ***/
html, body {
    margin: 0;
}

/*** Navigation ***/
.navbar {
    background-color: #ecf0f1;
    text-transform: uppercase;
    border-top: 5px solid #d1d064;
    letter-spacing: 3px;

    .navbar::after {
        content: '';
        clear: both;
        display: block;
    }

    .navbar > .main-nav > ul,
    li {
        /* styles */
    }
}

/* More CSS code goes here... */

Below is what I've attempted to translate into SCSS, acknowledging the need to use & followed by the >:

/*** External CSS ***/
@import "normalize.css";
/*** Page ***/
body,
html {
    margin: 0;
}
/*** Navigation Bar ***/
.navbar {
    background-color: #ecf0f1;
    text-transform: uppercase;
    border-top: 5px solid #d1d064;
    letter-spacing: 3px;

    &::after {
        content: '';
        clear: both;
        display: block;
    }

    & > .main-nav {
        max-width: 1480px;
        margin: 0 auto;
        text-align: center;

        /* Nested styles using '&' and '>' as expected */

    }
}



.fill {
    ul li a {
        /* Styles */
    }

    /* More nested styling */

}
@-webkit-keyframes fill {
    /* Keyframe animation properties */
}

Even after making adjustments following proper nesting rules, my code is still not functioning correctly. Any insights on what I might be doing wrong?

Thank you.

Solution Found For those new to SCSS like myself, note that you should not include SCSS code directly in your HTML file. Instead, use the compiled CSS file!

Answer ā„–1

When working with SCSS, utilizing the & selector is required to use the greater than symbol (>). An example of this would be .navbar { & > li {} }

Answer ā„–2

When nesting in scss, the symbol '>' will not be generated in the compiled output.

.class {
    .subclass {
        attribute: value;
    }
}

The above code will compile to:

.class .subclass {
    attribute: value;
}

However, you can use the '&' selector to achieve the desired result:

.class {
    & > .subclass {
        attribute: value;
    }
}

After compilation, the code will be transformed into:

.class > .subclass {
    attribute: value;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Expanding a list of object arrays through iteration: A step-by-step guide

// Initializing with one object let posi_val=[{top: '3px', left: '2px'}]; // Adding another object in the loop for (let i = 1; i < n; i++) { posi_val.push({ top: `${posi_val[i - 1].top.slice(0, -2) * 2}px`, l ...

What is the best way to duplicate a CSS shape across a horizontal axis?

I am working on decorating the bottom of my page with a repeated triangle design. The image provided only displays one triangle, but I would like to extend it across the entire horizontal div. Here is a screenshot of my progress so far: https://i.stack.im ...

Struggling with aligning images in the center while ensuring they remain responsive on various devices

My website has an image with dimensions of 955x955, which is a square size. I want this image to be responsive on all devices, but the section it's in is not squared. This causes the image to look distorted when viewed on smaller screens. The focus of ...

Ensuring uniform height of columns in Bootstrap

I want all columns following the first row with col-md-6 to have equal height, regardless of dynamic content (go to full page). <html> <head> <title>Page Title</title> <meta charset="utf-8"> <meta name="viewport" ...

Angular API data causing an undefined error in the template

When attempting to display values in an HTML template from API data, I encountered an issue. Despite not defining all the values in the object, the data is displayed correctly. However, an error appears in the console: TypeError: Cannot read property &ap ...

The "Add to Cart" button is non-responsive in the Ionic app

After purchasing the icymobi source code from codecanyon, I encountered an issue with adding a cart button to the wishlist page. Despite my efforts, the button does not add the product to the cart. https://i.stack.imgur.com/pqr7J.png The file in question ...

Utilizing a combination of PHP and jQuery, certain checkbox options were dynamically deactivated

<input type="checkbox" name="pref[]" value="red//fuji" />Fuji <input type="checkbox" name="pref[]" value="red//pinklady" />Pink Lady <input type="checkbox" name="pref[]" value="red//reddelicious" />Red Delicious <input type="checkbox" ...

Incorporating HTML5 audio elements in JavaScript

I am working on a project where I need to create a grid of 16 audio files with separate links for each in HTML, CSS and JavaScript. Each box in the grid should link to a different audio file. My initial thought was to use a table to achieve this, so I cre ...

5 Bootstrap Popovers with Custom HTML Contents

I am having trouble separating the content of the bootstrap5 popover from the HTML attributes, unlike other components where it is achievable. var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]')) var ...

Utilizing Twitter Bootstrap to populate form fields from a dropdown selection

I am currently using twitter bootstrap for my front end web development project. I have successfully implemented a text field with a dropdown menu right next to it: <div class="input-group"> <input type="text" class="form-control" name="ope ...

Using jQuery, you can activate an onclick function based on specific keywords entered by the user

Within this element, there is a text input field that allows users to search for specific items. Next to the input field is an icon image that can be clicked on to trigger a jQuery onclick event. This event sends an AJAX request to a PHP file, retrieves da ...

Creating a search field in Bootstrap 4 that emulates material design, facing challenges with transition animations

I tried to create a material design search field using Bootstrap form input. While I was able to make it work, I noticed a small issue with the focus state. When I click inside the field, the underline animation runs smoothly. However, when I click outside ...

PHP error: Index not defined

One challenge Iā€™m encountering is with a dating site form that includes the following categories: firstname,lastname,username,password,email,mysex,yoursex,relationship,date of birth, and country I've completed the PHP code to send information to a ...

HTML paired with AJAX response

Currently, I am tackling the situation described below: 1) I have an HTML page labeled A with an input of type text. 2) Upon selection, I trigger an Ajax call to another HTML page, B, in order to retrieve data from a MySQL database. 3) The retrieved dat ...

Arranging particular placement

How can I position my links to the right of the second photo (opus1) and slightly below the first photo (coverPhoto)? I've tried various methods but haven't found a simple solution yet. <!DOCTYPE html> <html lang="en"> <head ...

Saving the retrieved data from a JQuery $.post request into a JavaScript global variable

Currently utilizing Javascript and JQuery. A declaration of a Variable var RoleID=""; is stationed outside all functions. There exists a function: role_submit(){ var role=$('#emp_role').val(); var url="submitrole.php"; $.post(url, {role2: rol ...

What is the best way to set up user comments in a Mysql database?

Recently, I've been working hard on building a blog from scratch. However, I encountered a major issue with the comment section. The form prompts users to enter their Name and Comment, which are stored in the following database fields: `comname` VARC ...

Tips for choosing a drop-down menu option without an identifier using Selenium in Python

I am trying to choose an element/item from a drop-down menu in Python and Selenium without using an id element. Here is the HTML code snippet: <mbo-transaction-mode-select mode="filters.mode" class="ng-isolate-scope"> <select class="form-con ...

What steps should I follow to create a basic file upload page on my server?

Recently, I've been on a quest to create a straightforward file upload page that allows me to easily send files to my server. The concept is for the site to have a feature where I can simply upload a file and have it stored in a specific folder on the ...

jquery-powered scrollable content container

<script language="javascript"> $(document).ready(function($) { var methods = { init: function(options) { this.children(':first').stop(); this.marquee('play'); }, play: function( ...