Customizing twitter bootstrap popover arrow

后端 未结 4 1349
耶瑟儿~
耶瑟儿~ 2020-12-15 07:29

I could not find any relevant information on this, but I find it hard to swallow that it\'s not doable.

How can I customise the arrow for the popovers? I already did

相关标签:
4条回答
  • 2020-12-15 08:05

    I was having trouble adjusting popover border thickness. To adjust this I added the @popoverBorderThickness to popovers.less, only those lines are changed. I included the whole file for context.

    //
    // Popovers
    // --------------------------------------------------
    
    
    .popover {
      position: absolute;
      top: 0;
      left: 0;
      z-index: @zindexPopover;
      display: none;
      max-width: 276px;
      padding: 1px;
      text-align: left; // Reset given new insertion method
      background-color: @popoverBackground;
      -webkit-background-clip: padding-box;
         -moz-background-clip: padding;
              background-clip: padding-box;
      border: @popoverBorderThickness solid @popoverOuterColor;
      .border-radius(6px);
      .box-shadow(0 5px 10px rgba(0,0,0,.2));
    
      // Overrides for proper insertion
      white-space: normal;
    
      // Offset the popover to account for the popover arrow
      &.top     { margin-top: -10px; }
      &.right   { margin-left: 10px; }
      &.bottom  { margin-top: 10px; }
      &.left    { margin-left: -10px; }
    }
    
    .popover-title {
      margin: 0; // reset heading margin
      padding: 8px 14px;
      font-size: 14px;
      font-weight: normal;
      line-height: 18px;
      background-color: @popoverTitleBackground;
      border-bottom: 1px solid darken(@popoverTitleBackground, 5%);
      .border-radius(5px 5px 0 0);
    
      &:empty {
        display: none;
      }
    }
    
    .popover-content {
      padding: 9px 14px;
    }
    
    // Arrows
    //
    // .arrow is outer, .arrow:after is inner
    
    .popover .arrow,
    .popover .arrow:after {
      position: absolute;
      display: block;
      width: 0;
      height: 0;
      border-color: transparent;
      border-style: solid;
    }
    .popover .arrow {
      border-width: @popoverArrowOuterWidth;
    }
    .popover .arrow:after {
      border-width: @popoverArrowWidth;
      content: "";
    }
    
    .popover {
      &.top .arrow {
        left: 50%;
        margin-left: -@popoverArrowOuterWidth;
        border-bottom-width: 0;
        border-top-color: #999; // IE8 fallback
        border-top-color: @popoverArrowOuterColor;
        bottom: -@popoverArrowOuterWidth;
        &:after {
          bottom: @popoverBorderThickness * 1.414;// longer line gets thinner use Pythagorean theorem to correct
          margin-left: -@popoverArrowWidth;
          border-bottom-width: 0;
          border-top-color: @popoverArrowColor;
        }
      }
      &.right .arrow {
        top: 50%;
        left: -@popoverArrowOuterWidth;
        margin-top: -@popoverArrowOuterWidth;
        border-left-width: 0;
        border-right-color: #999; // IE8 fallback
        border-right-color: @popoverArrowOuterColor;
        &:after {
          left: @popoverBorderThickness * 1.414;// longer line gets thinner use Pythagorean theorem to correct
          bottom: -@popoverArrowWidth;
          border-left-width: 0;
          border-right-color: @popoverArrowColor;
        }
      }
      &.bottom .arrow {
        left: 50%;
        margin-left: -@popoverArrowOuterWidth;
        border-top-width: 0;
        border-bottom-color: #999; // IE8 fallback
        border-bottom-color: @popoverArrowOuterColor;
        top: -@popoverArrowOuterWidth;
        &:after {
          top: @popoverBorderThickness * 1.414;// longer line gets thinner use Pythagorean theorem to correct
          margin-left: -@popoverArrowWidth;
          border-top-width: 0;
          border-bottom-color: @popoverArrowColor;
        }
      }
    
      &.left .arrow {
        top: 50%;
        right: -@popoverArrowOuterWidth;
        margin-top: -@popoverArrowOuterWidth;
        border-right-width: 0;
        border-left-color: #999; // IE8 fallback
        border-left-color: @popoverArrowOuterColor;
        &:after {
          right: @popoverBorderThickness * 1.414;// longer line gets thinner use Pythagorean theorem to correct
          border-right-width: 0;
          border-left-color: @popoverArrowColor;
          bottom: -@popoverArrowWidth;
        }
      }
    
    }
    
    0 讨论(0)
  • 2020-12-15 08:07

    Twitter Bootstrap is based on Less.

    If you want to change the appearance of its arrows use the bootstrap less variables to do so.

    // Tooltips and popovers
    // -------------------------
    @tooltipColor:            #fff;
    @tooltipBackground:       #000;
    @tooltipArrowWidth:       5px;
    @tooltipArrowColor:       @tooltipBackground;
    
    @popoverBackground:       #fff;
    @popoverArrowWidth:       10px;
    @popoverArrowColor:       #fff;
    @popoverTitleBackground:  darken(@popoverBackground, 3%);
    
    // Special enhancement for popovers
    @popoverArrowOuterWidth:  @popoverArrowWidth + 1;
    @popoverArrowOuterColor:  rgba(0,0,0,.25);
    

    If you are using Sass instead do the same with the Sass Variables.

    Sadly the TB-Customizer doesn't have all the variables so you might have to compile it on your own.

    Edit:

    Good news the new Bootstrap 3 customizer now provides these options.

    0 讨论(0)
  • 2020-12-15 08:14

    Use these variables to customize tooltips:

    @tooltip-max-width:       200px;
    @tooltip-color:           #FFF;
    @tooltip-bg:              #000;
    @tooltip-opacity:         .9;
    @tooltip-arrow-width:     5px;
    @tooltip-arrow-color:     #000;
    

    Check the docs here: http://getbootstrap.com/customize/#tooltips

    0 讨论(0)
  • 2020-12-15 08:19

    For anyone using a custom style.css to simply overwrite bootstrap without recompiling the LESS, the css rule you're looking for is .popover.top > .arrow:after { border-top-color: yourColorHere; } to change the color of just the arrow.

    0 讨论(0)
提交回复
热议问题