Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9143631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:04:19+00:00 2026-06-17T10:04:19+00:00

I am trying to reuse a set of classes set inside a media query

  • 0

I am trying to reuse a set of classes set inside a media query as mixins to use throughout a website instead of embedding un-semantic class names in html.

Here is an example of my problem.

@media (min-width: 1000px) {

    .foo{width:120px;}
    .foo-2{width:150px;}
}
@media (max-width: 999px) {

    .foo{width:110px;}
    .foo-2{width:120px;}
}

.bar{.foo;}
.bar-2{.foo;}
.bar-3{.foo-2;}

the .bar-X will never get any styles applied. I can guess that this is happening because LESS doesn’t create .bar-X inside media queries, so nothing will ever be applied.

Is this a bug in LESS, or something I can never achieve? A workaround to this would be ideal.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:04:20+00:00Added an answer on June 17, 2026 at 10:04 am

    Your problem is a common misconception. LESS does not process the @media query, the browser does after LESS has done its work. LESS can only create the CSS code that the browser is going to read. So the @media is “meaningless” to LESS, it is just like any other selector (.someClass div table, etc.), it only processes what the @media is going to serve to the browser.

    So that means you need to put all your code that changes for the @media in the @media block. But you also don’t want a bunch of repeated code. So instead, create a master mixin to set your @media code, and then call that mixin from the media queries:

    .makeFooGroup(@w1, @w2) {
        .foo {width: @w1}
        .foo-2{width: @w2}
        .bar{.foo}
        .bar-2{.foo}
        .bar-3{.foo-2}
    }
    
    @media (min-width: 1000px) {
        .makeFooGroup(120px, 150px);
    }
    @media (max-width: 999px) {
        .makeFooGroup(110px, 120px);
    }
    

    Produces this css:

    @media (min-width: 1000px) {
      .foo {width: 120px;}
      .foo-2 {width: 150px;}
      .bar {width: 120px;}
      .bar-2 {width: 120px;}
      .bar-3 {width: 150px;}
    }
    @media (max-width: 999px) {
      .foo {width: 110px;}
      .foo-2 {width: 120px;}
      .bar {width: 110px;}
      .bar-2 {width: 110px;}
      .bar-3 {width: 120px;}
    }
    

    For some further info I’ve given on LESS and @media related to this, see:

    1. CSS pre-processor with a possibility to define variables in a @media query
    2. Media Query grouping instead of multiple scattered media queries that match
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to reuse a small chunk of code inside a custom button class.
I'm trying to reuse methods in DataMapper classes. This might be as well a
I'm trying to use PDO in this way and reuse the output template: selected_products_show
I'm trying to build a utility class that I can re-use, that converts a
I'm trying to have an abstract base class for some builder classes so I
I am trying to reuse shape data to dynamically create new shapes in code.
I am trying to reuse the header layout for contact details display view. I
I'm trying to reuse a group of Obj-C clases between iPhone applications. The values
I'm trying to re-use a Java generic collection I wrote, looks a lot like
I'm trying to figure out a way to re-use the validation rules of Yii's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.