Combining classes within LessCSS for nested functions

I'm struggling to get LessCSS to process a file with a series of nested rules using the "&" concatenation selectors.

For instance, the code below works fine:

.grey-table {
    background: #EDEDED;
    tr {
        th {
            background: #DEDEDE;
        }
        td {
            color: #888;
        }
        &:nth-child(odd) {
            td {
                background-color: #F9FCFF;
            }
        }
        &:nth-child(even) {
            td {
                background-color: #EDF5FF;
            }
        }
        &:hover {
            td {
                background-color: #DFEAF9;
            }
        };
    }
}

But when I try to use colors as functions (either predefined or mixins), I receive an error message:

"Syntax Error on line 12 - undefined"

 .grey-table {
    background: desaturate(#EDEDED, 100%);
    tr {
        th {
            background: desaturate(#DEDEDE, 100%);
        }
        td {
            color: desaturate(#888, 100%);
        }
        &:nth-child(odd) {
            td {
                background-color: desaturate(#F9FCFF, 100%); <------ Line 12
            }
        }
        &:nth-child(even) {
            td {
                background-color: desaturate(#EDF5FF, 100%);
            }
        }
        &:hover {
            td {
                background-color: desaturate(#DFEAF9, 100%);
            }
        };
    }
}

I have looked for solutions online but haven't found anything. Any help would be greatly appreciated.

Thank you!

Answer №1

I typically start by defining the colors and then use them in the functions:

@mycolor: #F9FCFF;
desaturate(@mycolor, 100%);

Apologies, but there doesn't seem to be any issues with your code on the less page:

Try pasting it in (without your <---line 12) and you will see that it works. It's possible that some JavaScript on your page is interacting with the less script.

Edit: You also have a semicolon at the end that can cause problems with older versions (<=1.3.1) of the less parser. When removed, it parses correctly across all versions ... and I cannot reproduce the error you are facing.

Answer №2

It seems I overlooked the tab on line 12 right after the colon.

This simple mistake was actually causing the error, particularly when a less css mixin or variable was present. My apologies for any confusion caused.

Answer №3

My thoughts align with Martin's. I have attempted to replicate the error using the code provided above and the compiler available at . Upon testing, the only scenarios in which a syntax error message on line 12 appears are as follows:

  1. If the colon following the background-color property is removed.
  2. Including unrelated characters after the closing semi-colon (similar to your note <--- line 12, although this input is incorrect, it seems you added it for clarification).
  3. Placing an additional quotation mark after the color, percentage, or parenthesis. For example, (b) - 100%'. While there may be other characters causing the issue, some simply get displayed in the CSS without triggering a syntax error.
  4. Inserting an unintended character separated by a space or any other invalid character before the property name, such as y background-color or *background-color.

Your provided code does not contain any of the mentioned issues. However, I suggest revisiting your actual code to ensure there are no unnoticed or misplaced characters leading to the problem.

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

Utilizing Pseudo Classes in Custom Styled Components with MUI

Exploring the world of React and MUI styled components for the first time. Currently, I'm delving into grid layouts and trying to style all children of a specific component. My goal is to target ${Item1}:nth-child(3n-1), ${Item2}:nth-child(3n-1), ${It ...

Is the Pure CSS hide/show technique using radio buttons causing a challenge with parent and descendant elements?

Exploring a CSS Show/Hide functionality using radio buttons is my current challenge. The snippet below demonstrates how smoothly it works. .refusal, .acceptance { display: none; } input#refusal:checked~.refusal { display: block; } input#acceptanc ...

Exploring the functionality of CSS class selectors (.class-name) when used alongside CSS tag selectors (div, etc...)

I have designed my website with three distinct tables, each requiring unique styling. The general approach I take to apply styling to these tables is as follows: import './gameview.css' <div className="game-results"> <h ...

Troubleshoot: Issue with Multilevel Dropdown Menu Functionality

Check out the menu at this link: The issue lies with the dropdown functionality, which is a result of WordPress's auto-generated code. Css: .menu-tophorizontalmenu-container { margin: 18px auto 21px; overflow: hidden; width: 1005px; ...

What is the process for designing custom width columns using Bootstrap?

I am working on a table with three columns that is styled using the Bootstrap class "table table-striped". However, I need the first column to be 100px in width, the second column to be 400px, and the third column to be 200px. How can I achieve this cust ...

Changing the text color and background color of a span element when a ng-click event is triggered

There are two buttons, Today and Tomorrow, each with an ng-click function. By default, the button background color is white and text color is red. When the Today button is clicked, the background color changes to blue and the text color changes to white. ...

What could be causing my div to display a horizontal scrollbar in Firefox?

Here's a straightforward test scenario: <html> <body> <div style="border:2px solid black; overflow: auto;"> x </div> </body> </html> Upon rendering, a horizontal scrollbar appears! I was using F ...

Exploring Angular's @Input feature for components buried deep within the hierarchy

As a newcomer to Angular, I am diving into the best approach for addressing a specific scenario. On my page, I have multiple tiles resembling mat-cards, each equipped with various functionalities such as displaying charts, tables, and associated actions. ...

What is the best way to position a website in the center in the provided example?

Simple question here, couldn't find it in the search so sorry if it's a repeat. How is the content on this responsive website centered? I've checked the body margins but can't seem to locate anything. Thank you for your help. ...

Tips for fading the text of list items when their checkbox is marked as done?

I am trying to figure out how to gray out a list item when its checkbox is checked. The code I currently have takes text input from a textbox and adds it to an unordered list when the add button is clicked. Each list item contains a checkbox within it. My ...

What is the best way to create a toggle button that can show more or show less of a text snippet with animation?

Is it possible for someone to assist me with showing a long text partially and providing a "show more" button to reveal the rest, along with a "show less" option, all with some CSS animation? I was thinking of using a font awesome arrow down icon for expan ...

Displaying vertical content with a horizontal scroll using Bootstrap

I have created a div container and I would like to implement a horizontal scroll bar when there are more than four items (each item consists of a picture with a title). Desired outcome: The issue I am facing is that by using the code below, I end up with ...

The contents table remains fixed in the top right corner as you scroll

I have developed an Angular app with a table-of-contents component that only displays two items. The code for the script is as follows: ts import { Component, OnInit } from '@angular/core'; import { pdfDefaultOptions } from 'ngx-extended-p ...

When I view the website on a tablet in landscape mode, the navigation bar vanishes

I just finished creating a responsive menu for a website. Here's how it works: when viewing the site on a regular browser with a width less than 768px, the navigation menu items are stacked and hidden. To reveal them, the user needs to click on a tog ...

Disregarding boundaries set by divisions

Trying to keep things concise here. I have a division called "the box" with a fixed width of 1200px that contains various other divisions. One of these divisions is a links bar, known as the "pink bar", which has a width of 100% and a height of 25px. My is ...

After uploading the WordPress theme, the wp_enqueue_style() function fails to work properly

I recently developed a new WordPress theme and encountered an issue while trying to load specific stylesheets for my child sites using the is_page(array('')) function in my function.php file. Surprisingly, only the files that were added to all of ...

Creating a customizable navigation bar using only CSS

I'm currently working on creating a navigation bar using only HTML and CSS, without the need for JavaScript to open and close it. However, I've encountered an issue where the navigation bar remains open even after setting display: none or visibi ...

using jquery to trap anchor in unordered list items

This section is dedicated to the menu on the website. The code for this menu can be found in the _Layout.cshtml() page. When the 'Neu Gesellschaft' page loads, I want to change the CSS of the anchor tag a. I attempted the following jQuery code: ...

jQuery appears to be unresponsive or inactive

I'm trying to implement a jQuery script that will slide in a header after scrolling on the page, but for some reason, it's not working. When I reach the 3rd line, my code editor displays a !read only alert, suggesting there may be a syntax issue? ...

How can you incorporate a custom button into the controlBar on videoJS in responsive mode?

The video player I have created using videoJS includes custom buttons in the control bar. These buttons are not clickable when viewed on mobile or tablet devices without forcing them to work. let myButton = player?.controlBar.addChild('button'); ...