What is the best way to structure multiple similar entries in CSS if arrays are not an option?

Apologies for the confusing question wording. It was flagged as spam and almost deleted.

I will have numerous entries similar to these:

span#CNQM {
        background: url(../../../../images/icons/sfc_CNQM.png) no-repeat top left;
    }
    span#HKBAM {
        background: url(../../../../images/icons/sfc_HKBAM.png) no-repeat top left;
    }
    span#SWBAM {
        background: url(../../../../images/icons/sfc_SWBAM.png) no-repeat top left;
    }
    span#DEAM2 {
        background: url(../../../../images/icons/sfc_DEAM2.png) no-repeat top left;
    }
    span#SFCQM1 {
        background: url(../../../../images/icons/sfc_SFCQM1.png) no-repeat top left;
    }
    span#SFCQM2 {
        background: url(../../../../images/icons/sfc_SFCQM3.png) no-repeat top left;
    }
    span#SFCQM3 {
        background: url(../../../../images/icons/sfc_SFCQM3.png) no-repeat top left;
    }
    

The list is becoming difficult to manage.

Is there a more efficient way in CSS to handle this rather than maintaining such a long list? In a scripting language, I would create an array (CNQM, HKBAM, SWBAM, etc.) and iterate through them.

If the answer is simply "that's how it works," that's fine, but if there is a better approach, I'm open to suggestions. Thank you.

Answer №1

In my understanding, CSS may not be able to provide a solution to this particular issue. This is why tools like LESS and SASS were created - I recommend utilizing one of them.

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

Error encountered when compiling SCSS with the '@use' statement

Currently, I am utilizing Gulp for the purpose of compiling scss into css. However, whenever I include a @use statement in my code, it does not compile the css correctly into the css file; instead, it simply duplicates the @use statement. What could be cau ...

Having trouble with the jQuery removeClass method?

Here is the HTML code I am working with: <div class="span-6"> <p> <table id="symptomTable" class="symptomsTable hidden"><th>Selected Symptoms:</th><tr></tr></table> </p> </div> T ...

Utilizing jQuery for adding/removing classes, however, elements are not refreshed to show changes

I am dealing with a situation involving two elements, similar to two buttons placed side by side. I am dynamically toggling the class "focusd" to alter the highlighted effect. However, I have noticed a peculiar issue where the changes are not always proper ...

Switch between different table rows

I have here a table that is used for displaying menu and submenu items. It's a mix of PHP (to fetch the menu items and their respective submenus) and HTML. What I am trying to figure out is how to toggle the visibility of only the submenu items under ...

How can the carousel item numbers be adjusted for proper display?

I'm currently working on an Angular app and have encountered a task related to displaying 5 cards using mdbootstrap. I want to showcase these cards in a carousel format, but with a twist - I only want the carousel functionality to be active on mobile ...

Concealing two out of three div elements inside a specified id container using jQuery

I have encountered an issue with my structure, which looks like this: http://jsfiddle.net/NEFhF/3/ This is how it should work: When I click on the "id contacts", the "field body" and the "field foot" should be hidden. However, the id and the field head b ...

using javascript to extract elements from an HTML table

I have some HTML code that I need help with. <td class=​"style1 product name" valign=​"top" nowrap>23$​</td>​, <td style=​"padding-left:​10px;​" class=​"product name" width=​"85%">productY</td>​ <td class= ...

Creating a sleek and dynamic bootstrap navigation bar with alignment challenges

I am facing an issue with the navigation bar I created using Bootstrap. It is not aligning as I want it to. I aim for it to be in line with the first image in the photo menu, which opens when you click on the camera icon. This alignment is important to me ...

Creating a hover effect for a row in Bootstrap 4 without relying on a table structure

Is there a way to make a row hover without using a table and instead utilizing the grid system in Bootstrap 4? I've done some research but everything seems to suggest that creating a table is necessary for this effect. <div class="row"> ...

ReactStrap: Rows and columns causing components to stack on top of each other

When I opt not to utilize Row and Col: <FormGroup> <InputGroup> <InputGroupAddon addonType="prepend"> <InputGroupText> ...

Ways to display an icon with an underline effect upon hovering over text

I have implemented a CSS effect where hovering over text creates an underline that expands and contracts in size. However, I now want to display an icon alongside the text that appears and disappears along with the underline effect. When I try using displa ...

Adjust the viewport width based on the width of the device

Having difficulty adjusting the meta tag viewport content width based on device width, I am struggling to achieve my desired outcome. Here is the code snippet I have been working with: Code snippet: <meta id="viewport" name="viewport" content="width=d ...

Gatsby utilized the background-image CSS style within the Emotion library for CSS-in-JS implementation

The background image is not visible with the current setup. To troubleshoot, I attempted to set the background to pink within const background and it worked. This confirms that Emotion is functioning correctly. Upon inspecting with the React Dev Tools ext ...

Troubleshooting Issues with Integrating Bootstrap Carousel

UPDATE: When I attempt to click on either the left or right icons, it unexpectedly scrolls me down to the bottom of the page. It seems to be related to the #truespeed aspect. The carousel functions perfectly when it is on a standalone page but causes issue ...

Having trouble applying CSS styles to the root element despite using a CSS file

My reactjs entry component setup looks like this: import React from "react" import ReactDOM from 'react-dom'; import App from "./js/components/App.js" import './index.css'; ReactDOM.render(<App />, document.getElementById(' ...

My grid layout isn't behaving as expected when using media queries

My current issue involves the implementation of a "main" element with a "grid" display property. I have configured two different layouts for this grid based on the screen size, as seen in the code snippet below: main { display ...

Centered div's overflow remains visible

Yes, the positioning of the parent container is set to relative. I am attempting to achieve a ripple effect by expanding multiple circles from a central point in all directions until they stretch beyond the viewport. I have created circular divs that are ...

Ways to enhance the vertical size of an svg graphic using css

Currently, I am focusing on manipulating an svg image (as depicted in the screenshot with an arrow indicating four triangles) within the html code showcased below, pertaining to the webpage where I aim to increase its height. https://i.sstatic.net/Ycgp0.p ...

Substituted the BR tag with a comma while including a space after the text

Upon further examination, I have observed that an extra space is being added when replacing the BR tag with a comma in the text: HTML: <div> one first <br class="hey"> two second <br class="hey"> three third </div& ...

Prevent clicks on the main div element while still allowing clicks on its nested elements with the same class

I have a div class called expandInnerDivStyle that I want to prevent clicks inside of. To achieve this, I am using the following code: $(".expandInnerDivStyle").css({pointerEvents: "none"}); However, there may be nested divs with the same class within th ...