Mike Mike - 15 days ago 4
CSS Question

How do I restrict my hovering style to only the button and not the entire table row?

I’m trying to create a different style for a button when you hover over it as opposed to when it is just sitting there. So I have created these styles

.btn {
font-family: "Montserrat","HelveticaNeue","Helvetica Neue",sans-serif;
font-weight: 400;
font-style: normal;
letter-spacing: 0.1em;
text-transform: uppercase;
padding: 12px 20px;
font-size: 0.8125em;
text-rendering: optimizeLegibility;
max-width: 100%;
margin: 0;
line-height: 1.42;
text-decoration: none;
text-align: center;
vertical-align: middle;
white-space: normal;
border: 1px solid transparent;
-moz-user-select: none;
-moz-appearance: none;
border-radius: 0;
background-color: #1c1d1d;
color: #fff;
text-indent: 0rem;
display: inline-block;
height: 1.42em; /* Same as line-height */
box-sizing: content-box;

.buttonContainer *:hover {
margin: 0 0 0px 0;
text-rendering: optimizeLegibility;
cursor: pointer;
background-color: silver;

This works, except when I hover over my button, the entire table row changes color — https://jsfiddle.net/eyettch5/ . Here is the HTML

<tr><td colspan="2" align="center">
<span class="buttonContainer"><form class="button_to" method="post" action="/user_race_time_matches/create?id=2194be1c-6831-4c8a-b096-34e25e6284bb" data-remote="true"><input class="btn saveDetails" value="Save" type="submit"><input name="authenticity_token" value="peb/GNeHaRFs+9DGeqbxRh5tK8yuURQLoN1cOZUEMmCvGyv6Nkpo9gPMjidbjCepZ79Kca44aV5Wrd9+i6NaiA==" type="hidden"></form></span>

What am I doing wrong and how can i get only the button in question to change color upon hovering?


Change your :hover target:

.buttonContainer .saveDetails:hover {}

The above should work.

Fiddle: https://jsfiddle.net/2fy02obk/