我正在尝试为按钮创建一种不同的样式,当您将鼠标悬停在按钮上时,而不是当它只是坐在那里时。所以我创造了这些风格
.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;
}
这有效,除了当我将鼠标悬停在我的按钮上时,整个表格行都会改变颜色 — https://jsfiddle.net/eyettch5/ .这是 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>
</td></tr>
我做错了什么,我怎样才能让有问题的按钮在悬停时改变颜色?
最佳答案
改变你的 :hover
目标:
.buttonContainer .saveDetails:hover {}
以上应该有效。
fiddle :https://jsfiddle.net/2fy02obk/
关于html - 如何将我的悬停样式限制为仅按钮而不是整个表格行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39987497/