Tips for customizing the appearance of multiple buttons to ensure they each stand out and function independently

body {
    background: url(http://i.imgur.com/LMYkPk3.jpg) no-repeat center center fixed;
    background-size: cover;
}

button {
    display:inline-block;
    margin: 0 10px 0 0;
    padding: 5px 20px;
    font-size: 15px;
    font-family: cursive;
    line-height: 1.8;
    appearance: none;
    box-shadow: none;
    border-radius: 20px;
}

button:focus {
    outline: none;
}

section.flat button {
  color: #fff;
  background-color: transparent;
  text-shadow: -1px 1px #417cb8;
  border: none;
}

section.flat button:hover,
section.flat button.hover {
  background-color: transparent;
    border: 2px solid orange;
}

section.flat button:active,
section.flat button.active {
  background-color: mintcream;
  text-shadow: -1px 1px #193047;
  color: black;
}
<!DOCTYPE html>
    <html lang="en">
      <head>
         <link rel="stylesheet" href="style.css" type="text/css"/>
            <title></title>
               </head>
             <body>
            <div id="line"></div>
            
<section class="flat">
    <button>button</button>
    <button>another</button> <!-- works fine if just one button ... but as soon as there more they all "selects" when hovered over one (change of depth ...) -->
    
</section>
   
     
            
        </body>
            
</html>

I'm facing an issue with two buttons on my page where they both seem to behave in the same way. When I hover over just one of them, both of them change their behavior in terms of depth. How can I prevent this from happening?

Answer №1

To ensure that each button is uniquely identifiable, you simply need to assign different IDs to them. This way, you can apply separate styles to each button based on their respective IDs. I have made some modifications to your code to demonstrate how this works:

<body>
        <div id="line"></div>

<section class="flat">
<button id="btn1">button</button>
<button id="btn2">another</button> 

  </section>
</body>
<!--the css-->
button {
display:inline-block;
margin: 0 10px 0 0;
padding: 5px 20px;
font-size: 15px;
font-family: cursive;
line-height: 1.8;
appearance: none;
box-shadow: none;
border-radius: 20px;
    }

   button:focus 
  {
outline: none;
   }
   #btn1 {
       background-color: #f0f0f8;
     }



    section.flat button:hover,
      section.flat button.hover {
     background-color: transparent;
      border: 2px solid orange;
        }

   #btn1:active,
    section.flat button.active {
     background-color: mintcream;
    text-shadow: -1px 1px #193047;
    color: black;
        }

I tweaked your CSS slightly to demonstrate functionality. The buttons now have distinct background-colors. Have a look at the updated fiddle below to see it in action. Enjoy!

Working JSfiddle

Answer №2

Ensure that each button has a unique id like

<button id="btn-1"></button>
,
<button id="btn-2"></button>
, etc. This will provide a distinct identifier for each button, preventing the CSS from targeting all buttons simultaneously instead of a specific one.

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

The peculiar scrollbar phenomenon caused by the CSS content-visibility attribute

After experimenting with the latest CSS property called content-visibility introduced in Google Chrome 85, I implemented it in my stylesheets to boost the rendering performance of my website: .my-page-section { content-visibility: auto; } However, a pec ...

Eliminating Redundant CSS Code Using PHP Storm

After upgrading to PHP Storm version 8.03, I came across an article that discussed the ability to search for duplicate CSS code using this link: . Although I have tried to find a way to automatically resolve these duplicate codes within PHP Storm, I have ...

Change classes of individual divs as one scrolls, with each div having its own distinctive class

I came across this article: Add/remove class with jquery based on vertical scroll? However, I am struggling to implement it for multiple divs, each with their own unique classes that require adding and removing 1 class at different distances from the top. ...

Tips for inserting line breaks in a variable received by pug

Is there a way to pass values including new lines into pug files? I have attempted to achieve this with the following code: var value1 = "value 1"; var value2 = "value 2"; var information = "\n" + value1 + "\n" + value2; res.render('pugfil ...

Having trouble loading CSS file in node js after submitting form

Before diving into more details, let me explain my current situation. I am utilizing node's nodemailer to facilitate the process of sending emails based on the information submitted through a form. Initially, everything was functioning smoothly when t ...

"Styling a play button on top of an image using CSS

Can someone please assist me in properly displaying a play button over a thumbnail using CSS in my WordPress site? I have tried various methods without success. Any guidance on where I may be going wrong would be greatly appreciated. .post-thumbnail-sid ...

Focus on a particular div in order to enable scrolling beyond its boundaries

Whenever I move my mouse over the div tag, I am able to scroll the content. However, if I move the mouse outside of the div box, scrolling stops. Is there a way to make the specific div element track the mouse pointer no matter where it goes? <div st ...

Designing a slider to display a collection of images

I am currently working on a slider project using HTML, javascript, and CSS. I'm facing an issue where only the first two images (li) are being displayed and it's not transitioning to the other (li) elements. Below is the HTML code snippet: <se ...

What could be causing my background image to vanish or flicker in Bootstrap?

Something unusual is happening with my website. There's a section with a static background image, and as you scroll, a quote and button (which will eventually link to a store) appear on top of it. Previously, this setup was working fine. However, yest ...

(adjust) upon selecting a different radiobutton

I have a dilemma with two radio buttons. I am trying to trigger an event when button B is either checked or unchecked. Unfortunately, I am unable to attach any event to button A. <input type="radio" id="A" name="radiogrp" v ...

Properly nested anchor elements with semantic meaning

I'm currently working on a web application where we are implementing inline editing. To illustrate the issue I'm trying to address, let's use the example of a Facebook post. For instance: Jennifer Lopez shared a new video The name "Jennif ...

What could be causing the issue with my php login page not functioning properly?

When I try to log in, the system does not verify whether the user login is successful or not. Instead, it redirects me back to the login page after entering my username and password. Also, the header location function doesn't seem to be working proper ...

Experiencing excessive sliding down of JQuery accordion repeatedly

I have a unique accordion feature that expands to display further information when each button is clicked. While it works fine, I am facing an issue where the box seems to slide up and down multiple times before showing the full content. Ideally, I would l ...

What is the best way to stack text boxes vertically in CSS/HTML?

How can I arrange these textboxes so that .textbox appears at the top, followed by textbox1 below? CSS .textbox { border: 1px solid #848484; -moz-border-radius-topleft: 30px; -webkit-border-top-left-radius: 30px; border-top-left-radius: ...

I'm interested in clicking on an image within a div to trigger a page refresh and then automatically hide the div once the page has refreshed

UPDATE 2 SITUATION To prevent access to quiz content until the page is refreshed, I am employing a semi-transparent image with a top-margin off-set. The following code functions flawlessly on one specific page and only once: JavaScript window.addEventL ...

jQuery Animation Issue: SlideDown Effect Not Working as Expected

I'm feeling quite confused about this situation. I've been attempting to utilize the slideDown function in jQuery, but when I click on the 'information' div, it just jumps instead of animating smoothly. I suspect that one of the cause ...

Displaying a loading GIF during a standard form submission

I am facing a challenge with a form in my concept, as it takes at least 10-15 seconds to load due to a large number of records. While I know I could use AJAX to display a loading GIF and load the records simultaneously, I am wondering if there is a way t ...

bootstrap for a responsive full-screen background image

I'm new to utilizing Twitter's Bootstrap. I am curious about the HTML layout required for implementing a full-screen responsive background image with Bootstrap. Currently, I am using the following mockup: <div class="container-fluid"> &l ...

Mobile device scrolling glitch

I'm currently working on my website, which can be found at . After testing it on mobile devices, I came across an issue that I just can't seem to fix. For instance, when viewing the site on a device with 768px width, you can scroll to the righ ...

Design the header and body of the table in a visually appealing format

$("input:checkbox:not(:checked)").each(function() { var column = "table ." + $(this).attr("name"); $(column).hide(); }); $("input:checkbox").click(function() { var column = "table ." + $(this).attr("name"); $(column).toggle(); }) <script src="h ...