【问题标题】:HTML CSS: Use Collapsible Toggle with SVG IconHTML CSS:使用带有 SVG 图标的可折叠切换
【发布时间】:2019-11-08 18:57:50
【问题描述】:

我想用 Google Materials SVG 图标替换 FontAwesome 图标,在按下可折叠表格按钮后(从向下箭头到向上箭头)。当前代码是这样的。我无法让 Google Material Icons 代码正常工作。我该如何解决这个问题?

应该像这样工作,除了谷歌图标:

https://codepen.io/tofanelli/pen/waadRY

字体真棒

.card-header .accordion-toggle:after {
    font-family: 'Glyphicons Halflings';
    content: "\e114"; 
    float: right; 
    color: grey; 
}


.card-header .accordion-toggle.collapsed:after {
    content: "\e113";
}

Google Material 图标:

.card-header .accordion-toggle:after .material-icons{
    content: "\e5cf"; 
    float: right; 
    color: grey; 
}


etc

切换按钮的图片示例:

【问题讨论】:

    标签: javascript html css twitter-bootstrap material-ui


    【解决方案1】:

    首先您需要包含 Google 网络字体

    <link href="https://fonts.googleapis.com/icon?family=Material+Icons"
          rel="stylesheet">
    

    在您需要替换的切换按钮的 css 定义中

    font-family: 'Glyphicons Halflings';
    

    通过

    font-family: 'Material Icons';
    

    最后

    content: "\e114"; 
    

    任一个

    content: "expand_less"; 
    

    content: "expand_more";
    

    这是一个基于您的代码的示例:

    .panel-heading .accordion-toggle:after {
      font-family: 'Material Icons';
      content: "expand_less";
      float: right;
      color: grey;
    }
    
    .panel-heading .accordion-toggle.collapsed:after {
      font-family: 'Material Icons';
      content: "expand_more";
    }
    <!-- Latest compiled and minified Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <div class="container">
    
    
      <div class="panel-group" id="accordion">
        <div class="panel panel-default">
          <div class="panel-heading">
            <h4 class="panel-title">
              <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
              Collapsible Group Item #1
            </a>
            </h4>
          </div>
          <div id="collapseOne" class="panel-collapse collapse in">
            <div class="panel-body">
              Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird
              on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table,
              raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
            </div>
          </div>
        </div>
        <div class="panel panel-default">
          <div class="panel-heading">
            <h4 class="panel-title">
              <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">
              Collapsible Group Item #2
            </a>
            </h4>
          </div>
          <div id="collapseTwo" class="panel-collapse collapse">
            <div class="panel-body">
              Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird
              on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table,
              raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
            </div>
          </div>
        </div>
        <div class="panel panel-default">
          <div class="panel-heading">
            <h4 class="panel-title">
              <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseThree">
              Collapsible Group Item #3
            </a>
            </h4>
          </div>
          <div id="collapseThree" class="panel-collapse collapse">
            <div class="panel-body">
              Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird
              on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table,
              raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
            </div>
          </div>
        </div>
      </div>
    
    
    </div>
    <!-- end container -->
    
    <!-- Latest compiled and minified JavaScript -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>

    【讨论】:

    • 谢谢,这很有帮助,还有一个问题,是否有.accordion-toggle。未倒塌或未倒塌的财产?出于某种原因,当我在我的解决方案中启动项目时,折叠时箭头为向上,但单击两次重置后,折叠时箭头变为向下,(正确方法)
    • 您可以通过手动将 collapsed 附加到关闭的 &lt;a&gt; 元素类来完成此操作。我修改了上面的示例。
    猜你喜欢
    • 1970-01-01
    • 2016-02-29
    • 2021-10-16
    • 2021-02-22
    • 2016-03-25
    • 1970-01-01
    • 2016-10-06
    • 2012-06-27
    • 1970-01-01
    相关资源
    最近更新 更多