【问题标题】:Using double arrows in a collapse menu在折叠菜单中使用双箭头
【发布时间】:2017-07-10 03:23:42
【问题描述】:

我想在折叠菜单中使用双箭头(左侧和右侧),但我不能。

您可以在此处找到折叠菜单示例:http://bootsnipp.com/snippets/b47p2

https://sedo.com/us/ 的“工作原理”部分中我想要的示例。

我试图解决 sedo 的代码,但我无法合并。据我了解,他们使用

_transform: rotate(135deg);_ 

做双箭头。

守则想要改变:

HTML:

<div class="container">
    <div class="row">
        <div class="col-md-8" id="main">
            <h3>Doesn't it look better ?</h3>
            <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
              <div class="panel panel-default">
                <div class="panel-heading" role="tab" id="headingOne">
                  <h4 class="panel-title">
                    <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                      Why is it better
                    </a>
                  </h4>
                </div>
                <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
                  <div class="panel-body">
                  <ul>
                      <li>The titles are block, so you don't have to click the text part to activate it</li>
                      <li>Indicators for expand / collapsing items</li>
                      <li>Removed title links' obnoxious :hover  underlinings, and outlines.</li>
                  </ul>
                </div>
                </div>
              </div>
              <div class="panel panel-default">
                <div class="panel-heading" role="tab" id="headingTwo">
                  <h4 class="panel-title">
                    <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
                      Collapsible Group Item #2
                    </a>
                  </h4>
                </div>
                <div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
                  <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" role="tab" id="headingThree">
                  <h4 class="panel-title">
                    <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
                      Collapsible Group Item #3
                    </a>
                  </h4>
                </div>
                <div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
                  <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>

            <hr />

            <h3>Compared to default</h3>

            <div class="panel-group" id="accordion_reg" role="tablist" aria-multiselectable="true">
              <div class="panel panel-default">
                <div class="panel-heading" role="tab" id="headingOne_reg">
                  <h4 class="panel-title">
                    <a role="button" data-toggle="collapse" data-parent="#accordion_reg" href="#collapseOne_reg" aria-expanded="true" aria-controls="collapseOne_reg">
                     Collapsible Group Item #1
                    </a>
                  </h4>
                </div>
                <div id="collapseOne_reg" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne_reg">
                  <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" role="tab" id="headingTwo_reg">
                  <h4 class="panel-title">
                    <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion_reg" href="#collapseTwo_reg" aria-expanded="false" aria-controls="collapseTwo_reg">
                      Collapsible Group Item #2
                    </a>
                  </h4>
                </div>
                <div id="collapseTwo_reg" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo_reg">
                  <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" role="tab" id="headingThree_reg">
                  <h4 class="panel-title">
                    <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion_reg" href="#collapseThree_reg" aria-expanded="false" aria-controls="collapseThree_reg">
                      Collapsible Group Item #3
                    </a>
                  </h4>
                </div>
                <div id="collapseThree_reg" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree_reg">
                  <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>
        <div class="sidebar col-md-4" id="sideright">
            <h3>Sidebar</h3>
            <p class="well">Some sidebar content</p>
        </div>
    </div>
<div>

CSS:

#accordion .panel-heading { padding: 0;}
#accordion .panel-title > a {
    display: block;
    padding: 0.4em 0.6em;
    outline: none;
    font-weight:bold;
    text-decoration: none;
}

#accordion .panel-title > a.accordion-toggle::before, #accordion a[data-toggle="collapse"]::before  {
    content:"\e113";
    float: left;
    font-family: 'Glyphicons Halflings';
    margin-right :1em;
}
#accordion .panel-title > a.accordion-toggle.collapsed::before, #accordion a.collapsed[data-toggle="collapse"]::before  {
    content:"\e114";
}

非常感谢..

【问题讨论】:

  • 你能贴出你目前拥有的代码吗?
  • 请在问题本身的minimal reproducible example 中提供所有相关代码,而不是在第三方网站上。
  • 这个效果是通过两张图片来实现的,你只需添加JavaScript代码,在点击标题栏时将图片从展开变为折叠。
  • @MikeMcCaughan 我添加了代码,谢谢。

标签: javascript jquery css twitter-bootstrap collapse


【解决方案1】:

将你的 css 更改为下一个

#accordion .panel-heading { 
    padding: 0;
    position: relative;
}
#accordion .panel-title > a {
    display: block;
    padding: 0.4em 2em;
    outline: none;
    font-weight:bold;
    text-decoration: none;
}

#accordion .panel-title > a.accordion-toggle::before, #accordion a[data-toggle="collapse"]::before,
#accordion .panel-title > a.accordion-toggle::after, #accordion a[data-toggle="collapse"]::after{
    content:"\e113";
    position: absolute;
    font-family: 'Glyphicons Halflings';
    top: 0.5em;

}
#accordion .panel-title > a.accordion-toggle.collapsed::before, #accordion a.collapsed[data-toggle="collapse"]::before,
#accordion .panel-title > a.accordion-toggle.collapsed::after, #accordion a.collapsed[data-toggle="collapse"]::after{
    content:"\e114";
}
#accordion .panel-title > a.accordion-toggle::before, #accordion a[data-toggle="collapse"]::before,
#accordion .panel-title > a.accordion-toggle.collapsed::before, #accordion a.collapsed[data-toggle="collapse"]::before {
    left: 0.5em;
}
#accordion .panel-title > a.accordion-toggle.collapsed::after, #accordion a.collapsed[data-toggle="collapse"]::after,
#accordion .panel-title > a.accordion-toggle::after, #accordion a[data-toggle="collapse"]::after{
    right: 0.5em;
}

【讨论】:

  • 感谢@Georgiy Dubrov。很酷的解决方案。我在 bootsnipp.com 上试过这个。它可以工作,但打开菜单后,所有箭头都向左移动。你也能解决这个问题吗?
  • 效果很好!非常感谢。您找到了折叠菜单的绝佳解决方案。我认为您也应该将解决方案添加到 bootsnipp.com。再次非常感谢你..
  • 编辑:嗨@georgiy-dubrov 和其他用户,我想问你一个新问题:如果您在面板标题中使用多于两行,那么右(第二个)箭头会结束最后一行(下)。我想在静态点上看到这个右箭头。我尝试使用 'vertical-align:top' 但它不起作用。你有解决这个问题的办法吗?
  • @user3620931 根据您的上一条评论对 css 进行了更改。请看一下
  • 嗨@georgiy-dubrov,你太棒了。非常感谢您的帮助。最新的代码效果很好。您应该在 bootsnipp.com 上分享您的解决方案。我从来没有见过像你这样的解决方案。再次感谢您...
猜你喜欢
  • 2020-06-03
  • 2021-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-01
  • 1970-01-01
  • 2020-11-16
  • 2010-12-27
相关资源
最近更新 更多