Rotating Glyphicons / Font Awesome in Bootstrap

前端 未结 5 1359
星月不相逢
星月不相逢 2021-02-07 05:19

I\'m trying to get the glyphicons in my bootstrap site to rotate on hover (in addition to changing color).

Here\'s my attempt: http://jsfiddle.net/young_greedo17/88g5P/<

相关标签:
5条回答
  • 2021-02-07 05:54

    The font-awesome.css file sets display: inline for your selector: [class^="icon-"], [class*="icon-"]. You can see this at line 161 of the CSS file:

    [class^="icon-"],
      [class*=" icon-"] {
      display: inline;
      width: auto;
      height: auto;
      line-height: normal;
      vertical-align: baseline;
      background-image: none;
      background-position: 0% 0%;
      background-repeat: repeat;
      margin-top: 0;
    } 
    

    Therefore you need to set the .widgetbox [class*="icon-"] to have a property display: block; http://jsfiddle.net/88g5P/6/

    EDIT: after looking up the differences between display:block; and display:inline-block;, I came upon this simple visual answer on Stack overflow. Based on this answer, it's probably better to use display:inline-block

    0 讨论(0)
  • 2021-02-07 05:54

    In your particular case the issue is that the icons you are using have display: inline-block, I added display:block to the custom CSS and it now works.

    0 讨论(0)
  • 2021-02-07 06:04

    New Font awesome introduced rotate notation http://fontawesome.io/examples/

    //Normal:
    <i class="fa fa-shield"></i>&nbsp; normal<br>
    
    //Rotated:
    <i class="fa fa-shield fa-rotate-90"></i>&nbsp; fa-rotate-90<br>
    <i class="fa fa-shield fa-rotate-180"></i>&nbsp; fa-rotate-180<br>
    <i class="fa fa-shield fa-rotate-270"></i>&nbsp; fa-rotate-270<br>
    
    //Flipped
    <i class="fa fa-shield fa-flip-horizontal"></i>&nbsp; fa-flip-horizontal<br>
    <i class="fa fa-shield fa-flip-vertical"></i>&nbsp; icon-flip-vertical
    
    0 讨论(0)
  • 2021-02-07 06:08

    The problem is that you're trying to transform an inline element - this isn't possible.

    You'll need to change the display value of the glyphicon to inline block.


    Here are the details from the CSS Transforms Module:

    transformable element

    A transformable element is an element in one of these categories:

    • an element whose layout is governed by the CSS box model which is either a block-level or atomic inline-level element, or whose display property computes to table-row, table-row-group, table-header-group, table-footer-group, table-cell, or table-caption [CSS21]

    • an element in the SVG namespace and not governed by the CSS box model which has the attributes transform, ‘patternTransform‘ or gradientTransform [SVG11]`

    0 讨论(0)
  • 2021-02-07 06:12

    you need to override the icon's display setting, since the rotation won't work on inline elements

    .widgetbox [class*="icon-"] {
    
         ...
    
         display:block;
    }
    
    0 讨论(0)
提交回复
热议问题