Can a CSS selector be created to target any of several potential identifiers?

My CSS code appears to be bulkier than necessary, and I'm wondering if there is a way to streamline it by using selectors that can target multiple identifiers.

For instance:

.scrollbar.horizontal:hover .button
{
}
.scrollbar.horizontal:active .button
{
}

I would like to simplify it to something like:

.scrollbar.horizontal:(active|hover) .button
{
}

Is there a syntax available for achieving this?

Answer №1

If combining the selectors doesn't work for you, then the answer is no:

.scrollbar.horizontal:hover .button, 
.scrollbar.horizontal:active .button {

}

Opting for a CSS preprocessor like LESS or SASS can help streamline the code:

.scrollbar.horizontal {
    &:hover, &:active {
        .button {
            ...
        }
    }
}

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

Achieving equal column heights with objects that fill the entire space

Check out this CSS playground for experimentation: https://www.bootply.com/HHeQ3n0EbT https://i.sstatic.net/WVUpI.png <div class="container"> <div class="row"> <div class="col ltg-column-parent"> ...

What is causing nested divs to generate a scrollbar?

I am struggling with a situation involving 3 layers of nested divs: <div class="outer"> <div class="inner"><div class="item"></div></div> </div> In this scenario, the .inner div is set to position absolute and each d ...

Tips for adjusting the size of a v-text-field within a d-flex layout in Vue

I'm a beginner with Vue and I have encountered an issue with two v-text-field elements in a flexbox. They are currently taking up the entire available space on a line when displayed side by side. However, I would like to make them smaller. Despite try ...

Is there a way to create a fallback for SVG in a CSS pseudoe

As I work on my website, I am incorporating some decorative elements using SVG images, but I am aware that certain browsers may not support them properly. That's why I want to ensure I have a PNG fallback in place. I am utilizing the :after pseudo-el ...

Looking for a tool or script that can easily convert CSS width and height values to the equivalent width="" and height="" attributes on elements?

I have been writing HTML emails and a key part of the process is converting my CSS inline. Despite searching for a solution to automatically convert CSS width/height properties into email tags, I have not found one yet. If there is a tool available that c ...

What is the best way to align two buttons side by side when they are each contained in separate forms?

Is there a way to align the submit buttons in two separate forms side by side? The first form should display as a block level element, while the second form can be inline-block. <form action="#"> <div class="form-group"> <lab ...

Page returning causing tabs to refresh improperly

Today I want to discuss two different pages: VelocityMicro.com/Cruz.php and VelocityMicro.com/PC.php, which I am currently viewing in Firefox. The issue I am experiencing is with Cruz.php. When you click on a tab like "R100 Series" and then select an acce ...

"Looking to spice up your website with a dynamic background-image

I've encountered a problem with my CSS code for the header's background image. Despite trying various methods to create a slideshow, nothing seems to be working. Can someone provide guidance? I have four banner images named banner1, banner2, bann ...

Stop the lower div from moving when the upper div is animated using ng-animate

I am facing an issue where the top div containing a title and a button fades away when clicked, revealing the bottom text. However, once the button disappears, the top div shrinks and the bottom div gets shifted upwards, leading to an undesirable layout. ...

The order of CSS precedence shifts even when the class sequence is the same

In my development setup, I have a react component that is embedded within two distinct applications each with their own webpack configurations. Within the component, I am utilizing a FontAwesome icon using the react-fontawesome library: <FontAwesom ...

JavaScript eliminates any existing CSS styling

I am new to the world of web development and recently created a sample webpage. The page consists of an HTML file, a CSS file, and a JavaScript file. However, I encountered an issue where linking the JavaScript file to the HTML page caused the CSS formatti ...

Sometimes, in extremely rare instances, external stylesheets may fail to download or be properly applied

There have been very rare occurrences where major websites like Amazon and Facebook do not load a CSS file or apply the rules correctly, resulting in pages looking incomplete: I was recently asked to provide an internal explanation after receiving a compl ...

What is the best way to target and select all spans within a specific div using JavaScript?

I'm struggling with selecting all spans in the card using code that currently only selects the first span when I use getElementsByTagName. Can anyone offer assistance as I have multiple cards containing spans? TypeError: Failed to execute 'inse ...

As soon as I integrated Bootstrap into my project, the color of the <li> tag became disordered and altered to a different hue

After integrating Bootstrap into my project, I noticed that the colors of the -li- tags became disordered and changed to a different color. How can I manage the colors while using Bootstrap in my project and also control them when hovering? <nav> ...

Creating a button with a side icon using Bootstrap

I have a simple question. I currently have a button: <button class="btn btn-warning" style="width: 20%; color: white"> <i class="fa fa-plus-circle"> <h5> <strong>Add Branch< ...

Utilizing nested tables to customize the appearance of cells within the primary table layer

I am facing a challenge with styling nested tables on my page. Specifically, I need to apply styles exclusively to odd rows of the top level table without affecting the tables within it. Unfortunately, I am unsure about how to accomplish this task. My ini ...

Troubleshooting Flex alignment problem caused by Slick Carousel Slider conflicting with Bootstrap

Today marks the beginning of my question asking journey. After dedicating almost a day to solving this, I humbly seek your assistance! :D My current challenge involves using Slick's carousel alongside Bootstrap. Whenever I add the 'slick-slider& ...

The touch event doesn't seem to be functioning properly on the div element, but it works perfectly on the window element

I have a dilemma that's been puzzling me lately. I'm trying to append a touchevent to a div, but my current method doesn't seem to be working. Here's what I've tried: $("#superContainer").bind('touchstart', function(even ...

Detecting the existence of a scrollbar within the document object model using JavaScript - a guide

Could someone provide a JavaScript syntax for detecting the presence of a scrollbar in the DOM by measuring the body height and window height? ...

Adjusting Google Maps API v3 Autocomplete dropdown width with JavaScript and SASS to match input field dimensions

I am facing an issue where the autocomplete dropdown (div with class "pac-container") is consistently 4 pixels shy of aligning perfectly with the right side of the input field. It looks like this: https://i.sstatic.net/Y0oq1.png Below is the HTML code: ...