【问题标题】:Change Background Color in Hover更改悬停时的背景颜色
【发布时间】:2015-05-28 04:41:14
【问题描述】:

目标:
将 "#" 和 "Firstname" 的第 th 设为悬停时的背景颜色为黄色

问题:
我不知道如何解决它。

信息:
在这种情况下,我不能使用<thead><body>,我使用的是 Bootstrap 和 jQuery。

.makeThisOpacity {
    opacity: 0;
}
.makeThisOpacity: hover {
    background-color: yellow;
}
<html lang="en">

<head>
    <title></title>
    <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.css" rel="stylesheet" />
    <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
    <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
</head>

<body>
    <br>
    <table class="table table-hover">
        <tr>
            <th class="makeThisOpacity">#</th>
            <th class="makeThisOpacity">>First Name</th>
            <th>Last Name</th>
            <th>Username</th>
        </tr>
        <tr>
            <td>1</td>
            <td>Mark</td>
            <td>Otto</td>
            <td>@mdo</td>
        </tr>
    </table>
</body>

</html>

【问题讨论】:

  • I do not know how to solve it. 嗯,首先你应该考虑让元素以某种方式可见然后......
  • 不透明度:0;使元素完全透明,使其在进程中不可见。

标签: jquery html css twitter-bootstrap


【解决方案1】:

.makeThisOpacity 在悬停时将 opacity: 0, 更改为 1

试试这个,

.makeThisOpacity {
    opacity: 0;
}
.makeThisOpacity:hover { 
    background-color: yellow;
    opacity: 1;
}

【讨论】:

  • opacity: 0; 使元素完全透明,使其在进程中不可见。
  • @connexo 但仍在处理任何鼠标事件,例如:jsfiddle.net/ybvvwaop
  • 当然,没有人说它没有。
  • @connexo 所以我不明白你之前的评论。那你是什么意思?
  • 它是针对 OP 以了解他做错了什么。
【解决方案2】:

Opacity: 0 将使文本完全不可见。

.makeThisOpacity {
    opacity: 0;// remove it
}

.makeThisOpacity:hover { 
     background-color: yellow;
     //if you want to use opacity as 0 then to display it increase your opacity, or else remove it.
     opacity: 0.5; // remove if your initial opacity is not 0.

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-12
    相关资源
    最近更新 更多