简体   繁体   English

如何在引导程序中将此fontawesome图标垂直对齐放置在标题div的中间

[英]How can I position this fontawesome icon vertically aligned in the middle of the header div in bootstrap

I have a search filter box in a collapsable component in bootstrap. 我在bootstrap中的可折叠组件中有一个搜索过滤器框。

The markup is as follows: 标记如下:

<div class="container">
<div class="col-xs-6">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
  <div class="panel panel-default">
    <div class="panel-heading panel-heading-pointer" role="tab" id="headingOne" data-toggle="collapse" href="#collapseOne" >
      <h4 class="panel-title">

      </h4>
          Search Filters<span style="padding-bottom:10px"><i class="fa fa-arrow-circle-down fa-2x floatRight"></i></span>

    </div>
    <div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
      <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>

The output of this looks like: 输出如下: 在此输入图像描述

I would like the fa-arrow-circle-down icon to be sat in with equal spacing at the bottom and top of the header div - such that it is sat in the middle of the header - like the text. 我希望fa-arrow-circle-down图标在标题div的底部和顶部以相等的间距坐着 - 这样它就像文本一样位于标题的中间。 I have tried adding margins, spans, paddings, but nothing seems to shift up the position of the icon! 我试过添加边距,跨度,填充,但似乎没有任何东西向上移动图标的位置!

Please help! 请帮忙!

The only custom style I have is the floatRight which is : 我唯一的自定义样式是floatRight,它是:

.floatRight{
    float:right;
}

Many thanks! 非常感谢!

I've added a .mycontainer class to the containing div . 我已经在包含div添加了一个.mycontainer类。 Then added span around the text and also the icon. 然后在文本和图标周围添加了span .mycontainer has display: table; .mycontainerdisplay: table; and span has display:table-cell; span display:table-cell; . This way you can then use vertical-align:middle; 这样你就可以使用vertical-align:middle; on the span elements. span元素上。

HTML : HTML

<div class="container">
<div class="col-xs-6">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
  <div class="panel panel-default">
    <div class="panel-heading panel-heading-pointer mycontainer" role="tab" id="headingOne" data-toggle="collapse" href="#collapseOne" >
      <span class="text">Search Filters</span>
      <span class="fa fa-arrow-circle-down fa-2x pull-right"></span>
    </div>
    <div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
      <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> 

CSS : CSS

.mycontainer {
  display:table;
  width:100%;
}

.mycontainer span {
  display: table-cell; 
  vertical-align: middle;
}

See Example . 例子

You can make your .panel-heading position relative: 您可以使.panel标题位置相对:

.panel-heading (
  position: relative;
}

Than just give to the icon following props in css: 而不仅仅是给css中的道具后面的图标:

position: absolute;
top: 50%;
right: 10px; //or how much you want it to be from the right
-webkit-transform: translate(0, -50%);
-ms-transform: translate(0, -50%);
transform: translate(0, -50%);

This will make the icon always be vertical centered (it doe not depends on icon's dimensions) 这将使图标始终垂直居中(它不依赖于图标的尺寸)

我会把它作为一个跨度并调整线高

A little late, but instead of adding classes, just use the bootstrap rows, cols correctly. 有点晚了,但不要添加类,只需正确使用bootstrap行,cols。 Just change the size of the col-sm-* to whatever. 只需改变col-sm- *的大小即可。 No point of adding css classes since you are already using bootstrap. 没有必要添加css类,因为你已经在使用bootstrap了。

<div class="container">
  <div class="row">
<div class="col-sm-12">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
  <div class="panel panel-default">
    <div class="panel-heading panel-heading-pointer mycontainer" role="tab" id="headingOne" data-toggle="collapse" href="#collapseOne" >
      <div class="row">
      <div class="col-sm-9">
        <span class="text">Search Filters</span>
      </div>
      <div class="col-sm-3">
        <span class="fa fa-arrow-circle-down fa-2x pull-right"></div>
      </div>
      </span>
    </div>
    <div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
      <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> 
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM