为什么这种遍历对我来说失败了?

Why this traversing is failing for me?

事情是这样的,我正在使用 scss,我正在尝试使用搜索框,有一个图标我想在你悬停和聚焦时改变他的颜色,

here you can see an example 我用我的代码为你们准备的

<div class="form-group">
    <input id="search-box" class="search-box">
    <label for="search-box">
        <span class="glyphicon glyphicon-search search-icon"></span>
    </label>
</div>

这里是 scss

$tl: .6s;

.search-box {
    background: lighten(get-color(plata), 10%);
    border: 0;
    border-radius: get-space(xxx-small) + 1;
    cursor: pointer;
    font-weight: $weight-light;
    height: get-space(x-medium);
    padding-left: get-space(small);
    transition: width $tl, border-radius $tl, background $tl, box-shadow $tl;
    width: 140px;

    label {
        color: darken(get-color(rose), 15%);
    }

    &:hover {
        border: 0;
        box-shadow: 0 0 .2px 1px get-color(plata);
        outline: none;
        transition: width $tl cubic-bezier(0, 1.22, .66, 1.39), border-radius $tl, background $tl;
        width: 200px;

        label .search-icon {
            color: darken(get-color(plata), 35%);
        }
    }

    &:focus {
        box-shadow: 0 0 0 1.4px get-color(cobalt-blue);
        color: get-color(night);
        cursor: text;
        outline: none;
        width: 200px;

        label .search-icon {
            color: get-color(cobalt-blue);
        }
    }
}

.search-icon {
    cursor: pointer;
    left: -30px;
    position: relative;
}

我不知道为什么我的遍历不起作用,我试图让 label .search-icon 捕获 hover / focus 事件并更改图标的颜色,但它没有这样做好吧,有什么建议吗?

根据您在 HTML 代码中的结构:

<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />

<div class="panel-heading first-panel-heading">
    <input id="sports-search-bar" type="search" ng-model="query" class="search-box" placeholder="Search sports...">
    <label for="sports-search-bar">
        <span class="glyphicon glyphicon-search search-icon"></span>
    </label>
</div>

您应该使用以下样式代码:

$tl: .6s;

.panel-heading
{
    .search-box {
        background: #ccc;
        border: 0;
        border-radius: get-space(xxx-small) + 1;
        cursor: pointer;
        font-weight: bold;
        height: get-space(x-medium);
        padding-left: get-space(small);
        transition: width $tl, border-radius $tl, background $tl, box-shadow $tl;
        width: 140px;

        &:hover {
          border: 0;
          box-shadow: 0 0 .2px 1px get-color(plata);
          outline: none;
          transition: width $tl cubic-bezier(0, 1.22, .66, 1.39), border-radius $tl, background $tl;
          width: 200px;
        }

        &:focus {
          box-shadow: 0 0 0 1.4px get-color(cobalt-blue);
          color: get-color(night);
          cursor: text;
          outline: none;
          width: 200px;
        }
    }

    label .search-icon {
        color: green;
    }

    label .search-icon {
        color: get-color(cobalt-blue);
    }

    &:hover
    {
        label .search-icon {
            color: blue;
        }
    }
}

.search-icon {
    cursor: pointer;
    left: -30px;
    position: relative;
}