The functionality of the button being disabled on hover and the cursor not responding accurately upon clicking

I need to apply the class name 'btn-common' to all buttons, followed by a common class 'btn' to each button. The width of each button should be set to 100px and the height to 40px, with the border removed and the border radius set to 10px.

  • For the first button, add the class name btn1 and set the cursor to pointer when hovering over it
  • Assign the class name btn2 to the second button, making it disabled with a disabled cursor when hovered over

I have completed everything except for the hover and click effects on the buttons, they are not functioning as expected.

.btn {
    width:100px;
    height:40px;
    border-radius: 10px;
    border: none;
}


.btn1{
  cursor: pointer;
}


.btn2:disabled{
   
  cursor: disabled;
}

.btn-common {
  float: left;
  margin: 10px;
}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="./style.css">
    <link rel="stylesheet" href="./common.css">
    <title>Button</title>
</head>

<body>
    <div class="root">
      <button class="btn-common btn btn1">Click me!</button>
      <button class="btn-common bnt btn2">Don't touch me!</button>
    </div>
</body>

</html>

Answer №1

.btn {
    width:100px;
  height:40px;
  border-radius: 10px;
  border: none;
}


.btn1{
  cursor: pointer;
}


.btn2:disabled{
   
  cursor:not-allowed;
}

.btn-common {
  float: left;
  margin: 10px;
}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8>
    <meta http-equiv="X-UA-Compatible" content="IE-edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="./style.css">
    <link rel="stylesheet" href="./common.css">
    <title>Button</title>
</head>

<body>
    <div class="root">
      <button class="btn-common btn btn1">Tap Here!</button>
      <button disabled class="btn-common btn btn2">Keep Off!</button>
    </div>
</body>

</html>

Answer №2

To implement this, you can simply define two additional classes: .pointer and .disable.

<html>
  <head>
    <meta charset="UTF-8" />
    <style>
      body {
        background: orange;
      }

      .btn {
        width: 100px;
        height: 40px;
        border-radius: 10px;
        border: none;
      }

      .btn-common {
        float: left;
        margin: 10px;
      }

      button.pointer {
        cursor: pointer;
      }

      button.disable:hover {
        cursor: not-allowed;
        opacity: 0.5;
      }
    </style>
  </head>
  <body>
    <div class="root">
      <button class="btn btn-common pointer">Click me!</button>
      <button class="btn btn-common disable">Don't touch me!</button>
    </div>
  </body>
</html>

Answer №3

cursor: disabled; is not a valid property, it should be changed to cursor: not-allowed;.

There is no need for additional classes in this case. You can achieve the desired effect by using the following CSS:

.btn {
    cursor: pointer;
}
.btn[disabled] {
    cursor: not-allowed;
}

Simply add the disabled attribute to the button element like this:

<button class="btn-common btn" disabled>Don't touch me!</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

Issues regarding aligning content vertically in flexbox

I can't seem to figure out this error, even though it seems simple. .box { display: flex; align-items: center; justify-content: center; } <div class="box"> <div><img src="https://via.placeholder.com/150x150" alt=""></di ...

Incorporating TypeScript basics into the if statement post compiling

As I delve into the Angular2 Quickstart, I stumbled upon a peculiar issue within app.component.js after compiling app.component.ts using tsc (version 1.8.2): if (d = decorators[i]) I am unable to pinpoint where I may have gone wrong in configuring the qu ...

Can someone assist me in streamlining a few parts of my JavaScript code

I have written some pretty complicated JavaScript code to dynamically create multiple input fields and dropdown boxes based on a number entered by the user in a text field. Here's a basic overview: the script checks if a number is being used, then d ...

Discovering the parameter unions in Typescript has revolutionized the way

My current interface features overloaded functions in a specific format: export interface IEvents { method(): boolean; on(name: 'eventName1', listener: (obj: SomeType) => void): void; on(name: 'eventName2', listener: (obj: Som ...

Is it a good idea to relocate the pagination to the top of the DataGrid in MUI

Can someone suggest a solution for moving the default pagination of XGrid above the table? Or do I need to develop my own custom pagination instead of using the built-in feature with XGrid? ...

Is it possible to generate a triangular attachment below a div element?

My designer sent me a unique design and I'm wondering if it's possible to replicate using HTML, CSS, or JavaScript? https://i.stack.imgur.com/spB71.png I believe it can be done with CSS by creating a separate div positioned absolutely under the ...

Increase the width of columns when hiding additional columns

I have the following HTML and CSS code. If one of the columns is hidden, I would like the other 3 columns to expand. I don't believe using col-md-3 will work in this situation. Is there a way to achieve this? <link href="https://stackpath.boots ...

The .click function in jQuery ceases to function after being utilized once

I've encountered an issue with my .click jQuery function. The desired behavior is that when I click the button, one div should be hidden (display:none) and another div should be shown (display:block). This works as expected the first time the button i ...

Any suggestions on resolving the "script timeout" issue while running a script using Python's SeleniumBase Library?

Recently starting to use Python, I am currently using Python's seleniumbase library to scrape a website and need to periodically run this fetch script. While experimenting, I encountered a script timeout error when the response time exceeded around 95 ...

Send the canvas image dataURL for decoding and saving on the server using AJAX in conjunction with PHP

In the front-end, an image is generated (canvas.toDataURL) from the content of a div: ... var img = new Image(); var dataUrl; img.onload = function() { ...

Vue automatically refreshes momentjs dates prior to making changes to the array

I am dealing with a situation where my child component receives data from its parent and, upon button click, sends an event to the parent via an event bus. Upon receiving the event, I trigger a method that fetches data using a Swagger client. The goal is ...

Tips for effectively handling color inheritance within Bootstrap 5

I need to customize Bootstrap 5 .text-success color for better contrast on my custom .bg-lvlN classes. Here is how I have defined them: .bg-lvl1 { background-color: #303333; } .bg-lvl2 { background-color: #222424; } /* Overriding .text-success c ...

Center align the division within the list item

Check out the fiddle provided here: https://jsfiddle.net/5jnnutg8/ I am looking for a way to center align and display inline the "something #" list items. While the title "Hi" can be centered using text-align: center in css, this doesn't seem to wor ...

Updating Bootstrap modal content based on button clickExplanation on how to dynamically change the content

I am looking to dynamically change the content displayed inside a modal based on the button that is clicked. For example, clicking button one will only show the div with the class 'one' while hiding the others. $('#exampleModalCenter&a ...

Transmit JSON information from one webpage and dynamically retrieve it from another page via AJAX while both pages are active

I am attempting to transfer JSON data from page1 when the submit button is clicked and then retrieve this data dynamically from page2 using AJAX in order to display it in the console. I am unsure of the correct syntax to accomplish this task. There was a s ...

Every time I attempt to send a request, I consistently encounter an error. The combination of React and MongoDB seems

Recently diving into the world of IT, I've been immersing myself in React and JavaScript by taking online video courses. As I was working on a website for one of these courses, I ran into various errors, particularly when trying to handle requests wit ...

Anomaly in the default checked state of checkboxes

I'm currently working on a project and encountering an issue with the code below. I need to incorporate a forEach() loop within getElements() instead of using map(). Additionally, I want the default state of a checkbox to remain checked even after nav ...

Styling a Pie or Doughnut Chart with CSS

I am working on creating a doughnut chart with rounded segments using Recharts, and I want it to end up looking similar to this: Although I have come close to achieving the desired result, I am encountering some issues: Firstly, the first segment is over ...

Experience the power of VueJS 3 with Pinia, all without the need

I've hit a wall. Despite scouring documentation and countless google searches, I can't seem to find the answer to this straightforward query: how do I install/import PINIA in a VUE application? Let's consider a basic VUE app: <div id=&qu ...

Guide to centering images with HTML and CSS

I've recently created a website with a homepage design that I'd like to tweak. Currently, the layout looks like this : https://i.stack.imgur.com/5UeUn.jpg My goal is to reposition the ficstore logo to the center and divide the bar into two halv ...