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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:50:45+00:00 2026-06-15T13:50:45+00:00

I am curently using LESS. Since I use CSS sprites, I wonder if LESS

  • 0

I am curently using LESS. Since I use CSS sprites, I wonder if LESS support this kind of syntax:

icon{x}{
  background-position:-10px -10*{x}px;
}

Since I have to create this CSS style:

icon1{
  background-position:-10px -10px;
}
icon2{
  background-position:-10px -20px;
}
icon3{
  background-position:-10px -30px;
}
.................
  • 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-15T13:50:46+00:00Added an answer on June 15, 2026 at 1:50 pm

    Is it possible ?

    Unfortunately, I think it’s not. LESS is a compiled language and doesn’t support (yet ?) iteration control structures like while() or for().
    To begin an answer, I would write the following HTML code :

    <div id="1" class="icon"></div>
    <div id="2" class="icon"></div>
    <div id="3" class="icon"></div>
    

    With the following LESS code :

    .dynamic-background(@i)
    {
        background-position: -10px (-10px * @i);
    }
    
    @var: `document.getElementsByClassName('icon')[2].id`;
    
    .icon
    {
        .dynamic-background(@var);
    }
    

    Which would result as the following CSS code :

    .icon
    {
        background-position: -10px -30px;
    }
    

    But as you can see, this code is dynamic for only one element by page, due to the [x] on the result of getElementsByClassName. Maybe there is an additional trick that I’m missing there, though.

    Alternative solution

    Maybe could you just use Javascript :

    <script type="text/javascript">
        var elems = document.getElementsByClassName('icon');
        for (var i=0; elems[i]; i++)
            elems[i].style.backgroundPosition = '-10px -'+elems[i].id*10+'px';
    </script>
    

    Which results in the following:

    <div id="1" class="icon" style="background-position: -10px -10px;"></div>
    <div id="2" class="icon" style="background-position: -10px -20px;"></div>
    <div id="3" class="icon" style="background-position: -10px -30px;"></div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using LESS CSS . I am currently using Mixins with variables. Something
Hi all patient developers using spring data graph. Since there is so less documentation
Currently using MySQL version 5.1.6 This is my first real world build and so
Can I parse LESS client side, and return the results? I am currently using
I'm currently using N0 to format my numbers. Is there a format to use
I'm currently using this code, and it does what I want it to $('#about-link').click(function()
Alright so to start this is strictly for Windows and I'd prefer to use
I'm using HMACSHA512 to hash data using a shared key. Since the key is
I'm currently using boost::intrusive_ptr together with my GUI classes. Although this is more or
Currently the formula I am using is below, but it is less accurate as

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.