代码之家  ›  专栏  ›  技术社区  ›  Ginger Squirrel

使用SCSS/CSS定位HTML元素时出现问题

  •  0
  • Ginger Squirrel  · 技术社区  · 8 年前

    style="float:right"

    我的HTML:

    <div class="panel-heading">
      <a data-toggle="collapse" data-parent="#accordion" href="#collapse1">
        <h4 class="panel-title">
          <i class="fa fa-picture-o" aria-hidden="true"></i>    
            Photography 
          <i class="fa fa-chevron-up" aria-hidden="true"></i>
        </h4>
      </a>
    </div>
    

    我想要 <i class="fa fa-chevron-up" aria-hidden="true"></i> 通过以开头的类为目标向右浮动 fa-chevron fa-chevron-down .

    .panel-heading {
        padding: $panel-heading-padding;
        border-bottom: 1px solid transparent;
        //@include border-top-radius(($panel-border-radius - 1));
        color: #000;
    
        > .dropdown .dropdown-toggle {
            color: inherit;
        }
    
    .fa {
        margin-right: 10px;
        color: $mogoturquoise;
    }
    
    a {
        h4 {
            color: #000;
    
              //Doesn't work
              i[class^="fa-chevron"] {
                float: right;
              }
    
              //Works
              .fa-chevron-up{
                float:right;
              }
            }
        }
    }
    

    为什么我的属性选择器不工作?这是SCS吗?

    3 回复  |  直到 8 年前
        1
  •  2
  •   Quentin    8 年前

    [class^="fa-chevron"] 是一个 substring matching attribute selector .

    它不针对类。它以属性为目标。

    类属性如下所示 class="fa fa-chevron-up" :它不是从 fa-chevron fa fa-chevron .

    `class="fa fx-chevron fa-chevron-up"`
    

    然后,可以使用常规类选择器将其作为目标:

    .fx-chevron {
    

    或者,您可以使用不同的子字符串属性选择器,该选择器未定位到字符串的开头。

    [class*="fa-chevron"]
    
        2
  •  2
  •   n1kkou    8 年前

    [class*="fa-chevron"]

        3
  •  1
  •   Ginger Squirrel    8 年前

    我发现:

    i[class^="fa fa-chevron"] {
      float: right;
    }
    

    修复了它。