Class Link works for what I am doing, however, it changes styling of all links on site

0

Issue

I have a site in WordPress where I am inserting a block with html.

This is the inserted html code:

<div class=“options-bar”>

<a href="https://total-speed-customs.myshopify.com/?" class=“options-bar-btn”>FUEL INJECTORS</a>
<a href="https://total-speed-customs.myshopify.com/collections/ignition" class=“options-bar-btn”>IGNITIONS</a>
<a href="https://total-speed-customs.myshopify.com/?" class=“options-bar-btn”>BOLTS</a>
<a href="https://total-speed-customs.myshopify.com/collections/e85-fuel" class=“options-bar-btn”>ELECTRONICS</a>
<a href="https://total-speed-customs.myshopify.com/collections/trailer-parts" class=“options-bar-btn”>WINCHES</a>

HITCHES

</div>

This is in the theme.css stylesheet at the very bottom:

.options-bar {
text-align: center; 

}

.options-bar-btn, a { display: inline-block; 
color: white !important;
text-decoration: none; 
background: black !important; 
padding: 10px 20px; 
margin: 0px 5px; 
border-radius: 6px;  
text-align: center;
font-size: 22px;

}

@media screen and (max-width: 500px)  {

.options-bar-btn, a { display: inline-block; 
color: white !important;
text-decoration: none; 
background: black !important; 
padding: 3px 3px; 
margin: 0px 1px; 
border-radius: 3px;  
text-align: center;
font-size: 10px;

}

}

It works for the inserted block html, but it also changes the styling of links sitewide. I’ve enclosed a link to the site in progress to show the row of buttons working correctly, but the top nav has the same styling, which needs to just be transparent for the logo and the main nav.

What am I missing?

https://total-speed-customs.myshopify.com/

Solution

Your expression .options-bar-btn, a {...} means the following: set the following styles to all elements that have class options-bar-btn and to all tags a as well.

The comma in your code is a separator between two rules.

When you need to set a rule for an element that is a child of an element with class options-bar:

.options-bar a {
   color: white !important;
}

This will select all a tags inside the elements with class options-bar.

If you want to change a style of all the links with class options-bar-btn:

a[class*="options-bar-btn"] {
    color: white !important;
}

This will select all tags a then filter elements that has options-bar-btn class set.

Answered By – Kirill

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More