The cursor: pointer and background-color change on hover are both not working on my buttons. I have tried the solutions i have seen to similar questions (swapped from a button tag to a anchor or div tag, changed the z-index) but none of them have helped. The rest of the styling is working fine so i don't understand why this is happening, please help.
.btn {
cursor: pointer;
position: relative;
display: inline-block;
width: 80px;
height: 30px;
background-color: #15181c;
border: none;
margin: auto 10px;
border-radius: 5px;
font-weight: bold;
color: white;
letter-spacing: 1.5px;
transition-duration: 0.3s;
padding: 5px 10px;
}
.btn:hover {
background-color: lightslategray;
}
.disabled {
opacity: 0.5;
}
<div class ="buttons">
<div class="btn">DEAL</div>
<div class="btn disabled">HIT</div>
<div class="btn disabled">STAND</div>
</div>
In case anyone else has this issue. I had a box shadow overlay to add a shadow on the background which was stopping the buttons from registering the mouse hover. Changing the button z-index to 100 didn't help, but when i changed the overlay index to -1 it solved the issue.
It's a bug on webkit browsers that doesn't allow you to see the hover effect.
You can do it in 2 ways: (You can do both)
Set the div.btn inside another div called for example div.btn-container and apply the hover to the parent element. This will surely work for you. (You can apply the hover to both of them)
Change the display: inline-block to display: inline. Inline sometimes causes some issues. (Sometimes)
.buttons {
display: flex
}
.btn {
position: relative;
/* SET THE DISPLAY TO INLINE-BLOCK */
display: inline;
width: 80px;
height: 30px;
background-color: #15181c;
border: none;
border-radius: 5px;
font-weight: bold;
color: white;
letter-spacing: 1.5px;
transition-duration: 0.3s;
padding: 5px 10px;
}
.btn-container {
margin: auto 10px
}
/* YOU CAN WRITE BOTH IN YOUR CSS FILE HERE */
.btn:hover {
cursor: pointer;
background-color: lightslategray;
}
.btn-container:hover btn {
background-color: lightslategray;
cursor: pointer;
border: 1px solid red
}
/* UNTIL HERE */
.disabled {
opacity: 0.5;
}
<div class="buttons">
<div class='btn-container'>
<div class="btn">DEAL</div>
</div>
<div class='btn-container'>
<div class="btn disabled">HIT</div>
</div>
<div class='btn-container'>
<div class="btn disabled">STAND</div>
</div>
</div>
The cursor: pointer and background-color change on hover are both not working on my buttons.
Is the code in the snippet the one you are using?
Since in the code snippet .btn:hover is working just fine?
Have you tried force-refreshing your browser.
Control + F5
You can also try running the page with a different browser.
Edit:
Based on the answers you have given to the other comments, I think it might be a system or browser bug. Here's a Jquery alternative if the pure css does not work in your system (if you are fine with using it).
.buttons {
display: flex
}
.btn {
position: relative;
display: inline;
width: 80px;
height: 30px;
background-color: #15181c;
border: none;
border-radius: 5px;
font-weight: bold;
color: white;
letter-spacing: 1.5px;
transition-duration: 0.3s;
padding: 5px 10px;
}
.disabled {
opacity: 0.5;
}
.btn:hover, .btn.jqHover {
background-color: lightslategray;
cursor: pointer;
border: 1px solid red
}
.activeElement {
background:#bfbfbf;
}
<div class="buttons">
<div class='btn-container'>
<div class="btn">DEAL</div>
</div>
<div class='btn-container'>
<div class="btn disabled">HIT</div>
</div>
<div class='btn-container'>
<div class="btn disabled">STAND</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function () {
var hoveredElement;
var clickedElement;
$(document).mousemove(function (event) {
hoveredElement=event.target.nodeName;
// comment this section in between to see issue
$(hoveredElement).mouseenter(function () {
$(this).addClass('jqHover');
}).mouseleave(function () {
$(this).removeClass('jqHover');
});
return hoveredElement;
});
$(document).click(function (event) {
clickedElement = event.target.nodeName;
return clickedElement;
});
});
</script>
Original Jquery answer by Sai
Related
The code I have for my button in HTML is this simple
What causes the button to not be able to be clicked, even though it is of type button?
.menubutton {
background-color: orange;
color: black;
text-align: center;
font-size: 20px;
padding: 20px 50px;
}
<button class="menubutton" style="position:absolute;left:10%" type="button"><b>Home</b></button>
The button is able to be clicked, as demonstrated by the following event listener:
document.querySelector(".menubutton").addEventListener("click", (e) => {
console.log("button was clicked!");
})
.menubutton {
background-color: orange;
color: black;
text-align: center;
font-size: 20px;
padding: 20px 50px;
}
<button class="menubutton" style="position:absolute;left:10%" type="button"><b>Home</b></button>
You probably mean that the user can't tell it's a button. To improve this, add a hover effect and pointer cursor to the CSS:
document.querySelector(".menubutton").addEventListener("click", (e) => {
console.log("button was clicked!");
})
.menubutton {
background-color: orange;
color: black;
text-align: center;
font-size: 20px;
padding: 20px 50px;
/* 👇 pointer on hover */
cursor: pointer;
/* 👇 transition */
transition: 0.2s ease;
}
/* 👇 hover event */
.menubutton:hover {
background-color: lightgrey;
}
<button class="menubutton" style="position:absolute;left:10%" type="button"><b>Home</b></button>
Read more about hover effects here and transitions here.
I don't think you need to add type=button on a button element.
You should add all the styles in the element in the <style> tag.
Using these changes, you should have:
HTML
<button class="menubutton">
<b>Home</b>
</button>
CSS
<style>
.menubutton {
position: absolute;
left: 10%;
background-color: orange;
color: black;
text-align: center;
font-size: 20px;
padding: 20px 50px;
}
</style>
I'm making a website and I'm trying to make the button center aligned, border-less, however, the css codes doesn't seem to effect the website
I have tried changing the class name, changing around the code and such. On the browser (google chrome) it shows that the code is "recognized" on the style but isn't being read
.qwerty {
background:#f4511e;
border: none;
color: white;
padding: 16px 32px;
text-align: center;
font-size: 16px;
margin: 4px 2px;
opacity: 0.6;
transition: 0.3s;
display: inline-block;
text-decoration: none;
cursor: pointer;
}
.button:hover {opacity: 1}
<div class="column" class="Border">
<form action="aboutme.html">
<button class="qwerty">ABOUT ME</button>
</form>
</div>
The button should have no border, orange, and increases opacity on hover
You treat button as a class (in the CSS part where you have a dot before "button"). You can either write either of these two:
// First solution
.qwerty:hover {opacity: 1}
//Second solution
button:hover {opacity: 1}
Here I'm trying to give you a brief about the CSS properties were working properly. You have to just manage the class name.
.column{
text-align: center;
}
.column .qwerty {
background:crimson;
border: 2px solid #000;
color: white;
padding: 16px 32px;
text-align: center;
font-size: 16px;
margin: 4px 2px;
opacity: 0.6;
transition: 0.3s;
display: inline-block;
text-decoration: none;
cursor: pointer;
}
.column .qwerty:hover {opacity: 1}
<div class="column Border">
<form action="aboutme.html">
<button class="qwerty">ABOUT ME</button>
</form>
</div>
.column {
width: 100%;
text-align: center;
}
use this. parent div must have a specific width to make child div it's center.
I have some cards and want to change the properties border-color and pointer-events when a user hovers a span tag which is inside a button tag.
This is no problem if i use a tag, see First Card on the left:
https://codepen.io/anon/pen/JzzEvj
However, when using a PRG pattern with form and button changing the pointer event and the border-bottom color when hovering does not work with Firefox. (See Second Card on the right side)
Any ideas how to fix this in Firefox?
Desired outcome see Card on the left:
The cursor should have pointer state when hovering the image
The cursor should have pointer state when hovering the card heading
The card heading's border-bottom color should change color when hovering the card heading
I spend a lot of time on this issue but only found this solution https://codepen.io/anon/pen/PLLWxJ which is not exactly the same, because
the card heading's border-bottom color changes when hovering any part of the card.
all parts of the card look clickable when hovering. The cursor state should only change to pointer when hovering the image or the card heading.
a {
text-decoration: none;
}
.product-cards-wrapper {
background: #fff;
padding: 64px 0;
}
.product-cards {
display: flex;
justify-content: center;
flex-wrap: wrap;
}
.product-card {
border: 1px dotted #ccc;
cursor: default;
margin: 0 16px 32px;
width: 250px;
text-align: center;
}
.product-card-img-wrapper {
align-items: center;
cursor: pointer;
display: flex;
justify-content: center;
height: 150px;
line-height: 0;
margin-bottom: 16px;
}
.product-card-heading {
border-bottom: 1px solid #e5e5e5;
color: #2bb3f0;
display: inline;
font-family: sans-serif;
font-size: 18px;
font-weight: 700;
line-height: 1.6;
text-align: center;
transition: border-color .2s;
}
.product-card-heading:hover {
border-color: #2bb3f0;
cursor: pointer;
}
.product-card-label {
background: #fee5ad;
border-radius: 99px;
color: rgba(0, 0, 0, .54);
cursor: text;
font-family: sans-serif;
font-size: 14px;
font-weight: 600;
margin-top: 4px;
padding: 2px 10px;
}
.product-card>button {
background: 0;
border: 0;
padding: 0;
width: 100%;
}
.product-card-heading {
border-bottom: 1px solid #e5e5e5;
color: #2bb3f0;
cursor: pointer;
transition: border-color .2s;
}
.product-card button .product-card-img-wrapper,
.product-card button .product-card-heading {
cursor: pointer;
}
.product-card button .product-card-heading:hover {
border-color: #2bb3f0;
}
.product-card-labels {
display: block;
font-family: sans-serif;
}
<section class=product-cards-wrapper>
<div class=product-cards>
<a class=product-card href=#>
<div class=product-card-img-wrapper>
<img src=https://via.placeholder.com/160x150 alt="">
</div>
<div class=product-card-heading>First Card</div>
<div class=product-card-labels><span class=product-card-label>Label</span></div>
</a>
<form class=product-card action=# method=post target=_blank>
<button name=l value=123>
<span class=product-card-img-wrapper>
<img src=https://via.placeholder.com/120x150 alt="">
</span>
<span class=product-card-heading>Second Card</span>
<span class=product-card-labels><span class=product-card-label>Label</span></span>
</button>
</form>
</div>
</section>
This was a six years old Firefox bug which was fixed in Firefox 66.
Children of the button tag now do respond to :hover. :)
I'm trying to create a page with a row of search filter buttons that always has one selected. The problem I'm facing is that if the mouse is clicked elsewhere on the page, the visibly selected button reverts to its default state and the user can no longer see which search filter is being applied. I'm using the css focus property, and maybe this is part of the problem, but I don't know how else to achieve what I want. Here's the relevant code:
#media screen and (min-width: 768px) {
.filters-group-wrap {
display: flex;
justify-content: space-between;
}
}
.btn {
width: 60px;
height: 60px;
background-size: cover;
display: inline-block;
border-radius: 30px;
-webkit-border-radius: 30px;
-moz-border-radius: 30px;
padding: 0px;
padding-top: 5px;
text-align: center;
line-height: 130px;
margin: 10px;
margin-top: 0px;
margin-bottom: 35px;
color: #888888;
font-size: 1em;
transition: .2s ease-out;
cursor: pointer;
border: none;
font-size: .8em;
}
#media (-moz-touch-enabled:0),(pointer: fine) {
.btn:hover {
color:#CCCCCC;
}
}
.btn:focus {
outline: none;
box-shadow: 2px 1px 4px 1px rgba(75,75,75,1);
}
#media screen and (max-width: 767px) {
.btn {
}
}
<div class="filter-options" data-toggle="buttons">
<button id="showA" class="btn" data-group="groupA" style="background-image: url('A.jpg')">A</button>
<button id="showB" class="btn" data-group="groupB" style="background-image: url('B.jpg')">B</button>
<button id="showC" class="btn" data-group="groupC" style="background-image: url('C.jpg')">C</button>
</div>
I'm using Bootstrap, so jQuery solutions are okay, although my understanding is limited. Thanks in advance.
Instead of working with the focus property, maybe you could use jquery to assign an "active" class to the button when is clicked.
If user clicks anywhere, the button remains active.
Check the code below
$(".btn").click(function(){ // when any button is clicked
$(".btn").removeClass("active"); //delete all "active" classes from all buttons
$(this).addClass("active"); //assign the "active" class only to the one that was clicked
return false;
}
Hope it helps.
The focus state works with the browser in a way you described above but you can try this using jquery or pure JS.
Define a css class that hold your desired focus state and the toggle the class on the child buttons of class filter-options.
Would like to here from you in case.
.active {
background: yellow;
border: 1px solid black;
outline-style: solid;
outline-color: red;
outline-width: thin;
}
#media screen and (min-width: 768px) {
.filters-group-wrap {
display: flex;
justify-content: space-between;
}
}
.btn {
width: 60px;
height: 60px;
background-size: cover;
display: inline-block;
border-radius: 30px;
-webkit-border-radius: 30px;
-moz-border-radius: 30px;
padding: 0px;
padding-top: 5px;
text-align: center;
line-height: 130px;
margin: 10px;
margin-top: 0px;
margin-bottom: 35px;
color: #888888;
font-size: 1em;
transition: .2s ease-out;
cursor: pointer;
border: none;
font-size: .8em;
}
#media (-moz-touch-enabled:0),(pointer: fine) {
.btn:hover {
color:#CCCCCC;
}
}
.btn:focus {
outline: none;
box-shadow: 2px 1px 4px 1px rgba(75,75,75,1);
}
#media screen and (max-width: 767px) {
.btn {
}
}
<div class="filter-options" data-toggle="buttons">
<button id="showA" class="btn" data-group="groupA" style="background-image: url('A.jpg')">A</button>
<button id="showB" class="btn" data-group="groupB" style="background-image: url('B.jpg')">B</button>
<button id="showC" class="btn" data-group="groupC" style="background-image: url('C.jpg')">C</button>
</div>
$("btn").click(function() {
$(this).toggleClass("active");
});
</script>
Thanks for the suggestions everybody. I was able to learn enough to get it working. For some reason, the class 'active' was an issue and I had to assign the function to 'button' to get it working. I don't know why, but it works now, so I'm not questioning it!
$("button").click(function(){
$("button").removeClass("pressed");
$(this).addClass("pressed");
});
I am currently customizing a wordpress theme.
Here my case, through a widget, I generate a div which has several classes :
<div class="col-lg-3 focus-box item-1">...</div>
The parent theme and bootstrap stylesheet already apply respectively properties on focus-box and col-lg-3 classes.
Well, I added to my child-theme stylesheet (which works well for many others things) this :
.item-1 { background-color: orange; }
And this does not work... nothing happen but I tried to do this in my child-theme CSS :
.col-lg-3 (or focus-box) { background-color: orange; }
.item-1 { background-color: orange; }
This way works... I really don't understand anything to what is happening here.
My Child-theme stylesheet is the last one to be load, so It should override all others, isn't it ?
If anyone has a clue, I would appreciate to get it :-)
Thanks in advance for your help.
Sommy
Thanks for your answers.
First, I already tried to use !important it didn't work, it was the same using stronger selector.
I know how to inspect code with my browser, and that's why I told you that my child-theme css was the last one to be loaded because I checked it.
The thing really weird, according to me, is that the result is different if I put col-lg-3 in my stylesheet or not.
I have similar issues with others HTML elements in my code.
To sum up :
My Child-Theme CSS is loaded after the parent-one
I checked it in my browser development tool
I also notice that the place where my CSS properties is change the result, if I put it at the end of my child-theme css it sometimes work example :
{
/* IF I PUT THE SELECTOR .focus-box .service-icon here It doesn't work */
/* SEE THE LAST ELEMENT BELOW */
.focus-box:nth-child(4n+1) .service-icon:hover {
border: 5px solid #e96656;
}
.focus-box:nth-child(4n+2) .service-icon:hover{
border: 5px solid #34d293;
}
.focus-box:nth-child(4n+3) .service-icon:hover {
border: 5px solid #3ab0e2;
}
.focus-box:nth-child(4n+4) .service-icon:hover{
border: 5px solid #f7d861;
}
.focus-box:nth-child(4n+1) .red-border-bottom:before {
background: #e96656;
}
.focus-box:nth-child(4n+2) .red-border-bottom:before {
background: #34d293;
}
.focus-box:nth-child(4n+3) .red-border-bottom:before {
background: #3ab0e2;
}
.focus-box:nth-child(4n+4) .red-border-bottom:before {
background: #f7d861;
}
.focus-box h5 {
margin-bottom: 15px;
color: #404040;
position: relative;
display: inline-block;
text-transform: uppercase;
margin-bottom: 30px;
font-weight: bold;
font-size: 17px;
float: none;
width: 100%;
background-color: rgba(224,82,6,0.2);
}
.other-focuses {
background: url(images/lines.png) repeat-x center;
margin-bottom: 25px;
}
.other-focuses .section-footer-title {
padding: 0 15px;
color: #404040;
font-weight: bold;
}
.other-focus-list {
padding-top: 5px;
margin-bottom: -17px;
}
.other-focus-list ul li {
display: inline-block;
margin-right: 50px;
padding-bottom: 15px;
text-transform: uppercase;
}
.other-focus-list ul li:last-child {
margin-right: 0;
}
.other-focus-list ul li i {
margin-right: 8px;
}
.item-dashboard {
padding: 20px 0 20px 0;
}
.focus-box p {
font-size: 14px;
color: black;
}
/* IF I PUT IT THERE THEN IT WORKS */
.focus-box .service-icon {
margin-bottom: 30px;
width: 145px;
height: 145px;
margin: auto;
border-radius: 50%;
border: 0px solid #ececec;
margin-bottom: 20px;
position: relative;
-webkit-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
Focus Box HTML Code :
<div class="col-lg-3 col-sm-3 focus-box item-dashboard" data-scrollreveal="enter left after 0.15s over 1s">
<div class="service-icon">
<a href="#">
<i class="pixeden" style="background:url(#/wordpress/wp-content/uploads/2015/10/cle_main_2.png) no-repeat center;width:100%; height:100%;"></i> <!-- FOCUS ICON-->
</a>
</div>
<!-- FOCUS HEADING -->
</div>
The question is why my child-theme CSS doesn't correctly override the parent one ? Why the place of my css element affect the result (I know the place affect if you override a property, but here it doesn't look like this...)
Thansk again for you help.
I finally overcame this issue by reviewing my style sheet loading priority and so on.
Thanks everyone.