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 7723935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:34:08+00:00 2026-06-01T04:34:08+00:00

I have the same block of code repeated with two different variables. This block

  • 0

I have the same block of code repeated with two different variables. This block of code is repeated many, many times so I was thinking to help manage this stylesheet I would convert it over to LESSCSS.

I am quite new with LESS CSS but am getting a compile error so I guess what I am trying to do is not possible they way I am approaching it.

.item(@name,@loc) {
    @name .icon { background: url(..) -24px @loc no-repeat; }
    .theme-purple @name .icon { background: url(..) 0 @loc no-repeat; }
    .theme-green @name .icon { background: url(..) -48px @loc no-repeat; }
    .theme-yellow @name .icon,
    .theme-orange @name .icon { background: url(..) -72px @loc no-repeat; }
    .theme-red @name .icon { background: url(..) -96px @loc no-repeat; }
}

.item('type',-24px);

Is something like this possible?

  • 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-01T04:34:10+00:00Added an answer on June 1, 2026 at 4:34 am

    You’re close. The first issue is your use of variables. You need to take a look at @arguments. I’m not 100% clear about what you are trying to accomplish (possibly some code for sprites), but let me give you an example:

    .box-shadow (@x: 0, @y: 0, @blur: 1px, @color: #000) {
      box-shadow: @arguments;
      -moz-box-shadow: @arguments;
      -webkit-box-shadow: @arguments;
    }
    
    .box-shadow(2px, 5px);
    

    You set your variables, followed by their default if they are not specified. Then you use @arguments to place them into your mixin. Since this is just a background image you will only have one. You then apply that mixin to a particular selector.

    It looks like you are trying to put mixins within selectors to use as a mixin, which isn’t possible. You also can’t place variables within selectors within selectors for a variety of reasons. The most important being scope. Variables are constants in LESS, so once you set that local global variable it can not be changed.

    It would be easier to maybe do it like this:

    .sprite (@path: url(..), @loc1: 0, @loc2: 0, @repeat: no-repeat;) { 
            background: @arguments;         
    }
    
    .foo { 
            .sprite('url(..)', -96px, -24px);
    }
    

    Should output:

    .foo {
            background: url(..) -96px -24px no-repeat;
    }
    

    Keep in mind you can not skip the first parameter in LESS arguments, so you will always need to declare the url in this example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a link to my previous question on this same block of code with
I have two types of buttons that I want to use the same code
I have the following code. Within the same block of code, I disable a
Is it possible to have same table name on different schema with different data
Can we have same delegate for two events ? which have same number of
I have this code if (hashtable_count(h) > 0) { do { kk = (key*)hashtable_iterator_key(itr);
I have global variables: point4 * mypoints; color4 * mycolors; And a block of
I have created my first Magento widget on a test site (same code and
since they have same rendering engine, this problem shows in both. it works great
I have a block of code inside a try catch block (c#). The block

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.