-1

I'm looking to make a html button darken in colour when hovered over.

The code I'm using is below:

<div style="width: 200px; color: white; background-color: #bf8f42; opacity: 0.8; margin: auto; margin-top: 0px; padding: 20px;">Training</div>

 

baines
  • 19
  • 1
  • 4
  • 3
    Possible duplicate of [How can I change a button's color on hover?](http://stackoverflow.com/questions/3898781/how-can-i-change-a-buttons-color-on-hover) – Vlusion Apr 20 '17 at 12:15
  • By not searching SO's vast archive of existing answers before posting your question, you waste your own time and the time of others who help you and who moderate you. Please practice better SO citizenship. – mickmackusa Apr 21 '17 at 20:31

6 Answers6

1

Try out this part of code:

<style>
div:hover{
background-color: #000000;
}
</style>
Vlusion
  • 79
  • 1
  • 14
1

you can give a class to your div element and add some styling in style tag in tag. Here is full HTML code for the button with a bit darken on hover

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
.btn-training
{
width: 200px; 
color: white; 
background-color: #bf8f42; 
opacity: 0.8; 
margin:0 auto;
padding: 20px;
text-align: center;
}
.btn-training:hover
{
background-color: #9f7f31;
}
</style>
</head>
<body>
<div class="btn-training">Training</div>
</body>
</html>
  • Please edit your answer to include some explanation. Code-only answers do very little to educate future SO readers. – mickmackusa Apr 21 '17 at 20:27
0

Explanation:

When the user hovers over the class (test) it triggers the css element .test:hover. :hover is a anchor pseudo-class. you can use these types of classes in various ways Shown Here.

.test:hover {
    background: #000000;
}
<div class="test">text</div>
    
  • Please edit your answer to include some explanation. Code-only answers do very little to educate future SO readers. Your answer is in the moderation queue for being low-quality. – mickmackusa Apr 21 '17 at 17:01
  • K, will do. But also every other answer on this question doesn't have a explanation of what the code does. –  Apr 21 '17 at 18:10
0

Try something like this,

div:hover{
  background-color: #000000;
  opacity:1;
}
Ahmed Ginani
  • 6,522
  • 2
  • 15
  • 33
  • Please edit your answer to include some explanation. Code-only answers do very little to educate future SO readers. – mickmackusa Apr 21 '17 at 20:27
0

This code might help you for changing colors while hovering

<!DOCTYPE html>
<html>
<head>
<style>
input:hover {
    background-color: yellow;
}
</style>
</head>
<body>

       <input type="button"  /> 

 </body>
</html>
Shabarish Shetty
  • 132
  • 2
  • 12
0
Try this solution:
    .btn-test {
      width: 200px;
      color: white;
      background-color: #bf8f42;
      opacity: 0.8;
      margin: auto;
      margin-top: 0px;
      padding: 20px;
    }

    .btn-test:hover {
      background-color: #a26d19;
    }
 <div class="btn-test">Training</div>
  • This worked, however I can't seem to increase the button size plus it moves another button the the right. @vinod joshi – baines Apr 20 '17 at 12:52
  • Please edit your answer to include some explanation. Code-only answers do very little to educate future SO readers. – mickmackusa Apr 21 '17 at 20:26