jquery - 如何在悬停时更改不同元素的 css?

标签 jquery css hover

我正在创建一个看起来像这样的温度计图形:

enter image description here

并在悬停时突出显示温度计的一部分。问题是第一个片段是由两个重叠的 div 创建的。这意味着当我将鼠标悬停在第一段上时,会发生这种情况:

enter image description here

当用户将鼠标悬停在其中时,如何编辑我的 CSS 以突出显示第一段和温度计开头的圆圈?我更喜欢基于 css 的解决方案,但如果那不可能,我很乐意改用 javascript/jquery。下面是当前的 HTML 和 CSS。

<div class="thermo">
    <div class="startthermo">&nbsp;</div>
    <div class="thermopadding">&nbsp;</div>
    <div class="thermalcapsule" style="width: 10%">
        <div class="thermal thermal1">1</div>
        100
    </div>
    <div class="thermalcapsule" style="width: 15%">
        <div class="thermal thermal2">2</div>
        200
    </div>
    <!-- More HTML here -->
</div>

.thermo {
    width: 95%;
    margin-left: auto;
    margin-right: auto;
}

.thermalcapsule {
    margin-right: 1px;
    margin-top: 20px;
    float:left;
    text-align: center;
    cursor: pointer;
    position: relative;
    z-index: 1;
}

.thermalcapsule:hover .thermal1{
    background-color: #000000;
}

.thermoimage {
    margin-left: -15px;
    margin-top: 8px;
    float: left;
}

.thermopadding {
    width: 2%;
    float:left;
}

.startthermo {
    width: 50px;
    height: 50px;
    border-radius: 50px;
    background-color: #60A4CE;
    border: 9px solid #f4f4f4;
    display: block;
    float:left;
    position: absolute;
}

.thermal {
    width: 100%;
    padding: 5px;
    text-align: center;
    color: #fff;
    font-weight: bold;
    position: relative;
    z-index : 5;
}

.thermal1 {
    background-color: #60A4CE;
}

.thermal2 {
    background-color: #437C87;
}

最佳答案

我是这样解决这个问题的,希望对你有帮助:

http://jsfiddle.net/bVDVm/

<div class="thermo">
    <div class="thermopadding">&nbsp;</div>
    <div class="thermalcapsule" style="width: 15%">
        <div class="startthermo">&nbsp;</div>
        <div class="thermal thermal1">1</div>
        100
    </div>
    <div class="thermalcapsule" style="width: 15%">
        <div class="thermal thermal2">2</div>
        200
    </div>
    <!-- More HTML here -->
</div>

.thermalcapsule:hover .startthermo,
.thermalcapsule:hover .thermal1{
    background-color: #000000;
}

.startthermo {
    width: 50px;
    height: 50px;
    border-radius: 50px;
    background-color: #60A4CE;
    border: 9px solid #f4f4f4;
    display: block;
    float:left;
    position: absolute;
    margin-left: -35px;
    margin-top: -20px;
}

关于jquery - 如何在悬停时更改不同元素的 css?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18271653/

相关文章:

jquery - 每次按键jQuery检测输入是否有文本

html - 悬停在第一个 div 上时需要将悬停应用于第二个 div

javascript - 将变量从悬停传递到悬停

html - css hover 想显示一个框

javascript - 用红色突出显示负数

javascript - 元素阻塞滚动事件

jquery - 如何在不影响图像可见性的情况下减小整体尺寸?

html - 如何在 css 中内联显示标题和段落元素?

html - MVC 4 中的样式复选框

html - 在指定的 div 中启用滚动?