Can one incorporate duplicate style within a .less component?

Are there ways to consolidate CSS styles within a component for reuse in multiple locations? Take the instance below, where the same style is being duplicated for the .navigation class:


.container-1 {
    .navigation {
        width: 100%;
    }
}

@media (max-width:991px) {
    .container-1 {
        .navigation {
            margin-top: 0px;             // <-- repeated
            background-color: #252525;   // <-- repeated
            width: 250px;                // <-- repeated
        }
    }
}

.container-2 {
    .navigation {
        margin-top: 0px;             // <-- repeated
        background-color: #252525;   // <-- repeated
        width: 250px;                // <-- repeated
    }
}

Answer №1

If you want to streamline your code, consider using the power of Mixins:

.navigation-styles {
  margin: 0;
  padding: 0;
  list-style: none;
}

@media (max-width:991px) {
    .container-1 {
        .navigation {
             .navigation-styles();
        }
    }
}

.container-2 {
    .navigation {
        .navigation-styles();
    }
}

For more information on Mixins in Less, check out the documentation here

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

When Ruby on Rails is combined with HTML and CSS and marked as selected, it will be displayed with

I'm currently in the process of developing my cookbook app and the next feature on my agenda is the grocery list functionality. Once on the recipe page, users will have the option to click on an "Add to Grocery List" link which will redirect them to a ...

Encountering issues with the functionality of my Bootstrap navbar

After diving into the world of bootstrap, I encountered some challenges with the navigation bar in mobile view. Despite adding a navbar and a toggle button, it doesn't seem to be functioning correctly. Following tutorials and examples meticulously, bu ...

Arrange SVGs using CSS in a grid with offsets

My current project involves creating a background using SVGs in React. I'm looking for an easy CSS method to arrange these icons in a grid, possibly with an offset for the second row. I also need the width of the icons to be dynamic so that they adj ...

Within the flask framework, I am experiencing an issue where paragraphs are being overwritten. My goal is to find a

Snippet of HTML: <div class="split left" > <div class="centered"> <div class="container"> <p>Hi!</p> </div> <div class="darker"> <p>{{message}}& ...

Tips for efficiently printing invoices on specific paper: Print a maximum of 20 items per sheet, and if it exceeds this limit, continue onto the next page. Ensure the total amount is

$(document).ready(function(){ var j = 23; for (var i = 0; i < j+11; i++) { if (i != 0 && i % 11 == 0) { $("#printSection div").append("<?php echo '<tr><td>fff</td></tr>'; ?>"); ...

Using transparent rgba overlay in CSS

<!doctype> <html> <head> <style> div { background:rgba(0,255,255,0.3); } #div1 { width:300px; height:300px; } #div2 { width:200px; ...

The button on the master page is not able to be accessed when it is covered by a div tag on the Home page of an ASP.NET website

On my home page, I have a div tag containing a login form. In the master page, there is a signout button. After the user logs in, the text box and label used in the login form are hidden, and the signout button becomes visible. However, I am facing an issu ...

Utilize Bootstrap's toggle button in the navigation bar to smoothly shift the content to the left

Recently, I encountered an issue with the navbar on my website. In the mobile version, whenever the toggle button in the navbar is clicked, it results in the website shifting to the left and causing the content to be off-center. However, when I view the w ...

What are the steps for troubleshooting LESS in Chrome?

It appears that the art of LESS debugging has made significant progress in the last year, and I am curious to know how many people have experience using developer tools in Chrome/Canary for debugging. My goal is to make sure that when I debug a file, the ...

What is the method for changing the color of a specific section of a header?

My header design consists of two lists of buttons, one on the left and one on the right. I am looking to customize the background color of the "Sign Up" button to make it stand out. Below is an example of what I want and the current design of my header alo ...

Having difficulty showing images from the static folder in Django

https://i.sstatic.net/rpHZg.pngThis page is my home.html Unfortunately, I am facing an issue with displaying the images located in the static/images/ directory. Even though *[09/Mar/2020 15:52:09] "GET /static/images/mona.jpg HTTP/1.1" 404 1669 ...

Creating a collection of footer buttons using CSS within Element UI

Struggling to recreate this layout using CSS, specifically with the footer buttons. https://i.sstatic.net/etG51.png Here's what I've achieved so far using the el-card component of Element UI and CSS: <el-card> <div style="cur ...

Adjusting an HTML table to fit within a designated space

I am currently in the process of constructing an HTML table that will showcase data retrieved from a MySQL database. This table will include functionalities to update or delete rows within the database. Here is a glimpse of my code: <table> <tr& ...

Is there a way to horizontally align the content in my footer section?

I am currently exploring React Material UI for the first time. The table I am working with can be found here under the "Custom pagination actions" section. Within this section, there is footer content containing buttons for rows per page, next, previous, ...

Contrasting the process of generating DOM elements by using createElement, setting properties, etc., versus constructing a string of elements and then appending them

I am curious about the distinction between these two methods for creating HTML elements. I cannot seem to find any difference. I simply want to understand if there are any variations based on performance or any other factors. The first technique involves ...

What is the best method for gathering information from multiple input fields?

I'm currently working on developing a Polymer application that includes a search button with multiple input boxes. I want the search operation to consider all the inputs from these boxes when performing a search. Here is an image depicting the scenar ...

What is the best way to add color to the "ngx-star-rating" component?

I've been experimenting with the ngx-star-rating plugin, and I've tested different approaches like fill and color, but nothing seems to be working! Can anyone provide suggestions on how to change the star rating color from yellow to a different c ...

Tips for implementing vertical scrolling in a Windows 8 app when in snapped view

Currently, I am developing a Windows 8 application using Html, CSS, and JavaScript. Upon entering snapped view, certain screens are unable to display the entire content, leading me to seek a solution for vertical scrolling. Is there a way to address this ...

What is the best way to eliminate the blue border surrounding the input element in Bootstrap 4?

https://i.sstatic.net/a5BKg.png I have noticed that when I click on the input field, a blue border appears around it. Is there a way to remove or change this border? <div class="input-group mb-3"> <input type="tex ...

conceal the starting and ending markers for text separators

Here are two different methods to tackle this issue: one using pure CSS and the other utilizing jQuery. These solutions will allow for any symbol or image to be used as a separator. Note: Creating and finding solutions for questions like these can be quit ...