Changing bootstrap caret(color and position)

前端 未结 7 2364
广开言路
广开言路 2021-02-12 14:24

I want to change color of caret and make it not relative from input text, because it\'s hard to make it look good when it is.

相关标签:
7条回答
  • 2021-02-12 14:38

    Refer to this post: How do CSS triangles work?

    For example, the standard "down" arrow provided by bootstrap uses the following style:

    <span class="caret"></span>
    
    .caret {
      display: inline-block;
      width: 0;
      height: 0;
      margin-left: 2px;
      vertical-align: middle;
      border-top: 4px solid #000000;
      border-right: 4px solid transparent;
      border-bottom: 0 dotted;
      border-left: 4px solid transparent;
      content: "";
    }
    

    Here I have just transposed the borders a bit, and now it is an "up" arrow. The same approach can be done for right and left carets.

    <span class="up_caret"></span>
    
    .up_caret {
      display: inline-block;
      width: 0;
      height: 0;
      margin-left: 2px;
      vertical-align: middle;
      border-bottom: 4px solid #000000;
      border-left: 4px solid transparent;
      border-top: 0 dotted;
      border-right: 4px solid transparent;
      content: "";
    }
    

    Hope this helps!

    0 讨论(0)
  • 2021-02-12 14:41

    Not the best way but it should work:

    Add this to your stylesheet (CSS) after the Bootstrap include.

    .btn-primary .caret, .btn-warning .caret, .btn-danger .caret, .btn-info .caret, .btn-success .caret, .btn-inverse .caret {
    
        border-top-color: red;
    
        -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
        filter: alpha(opacity=100);
        -moz-opacity:1;
        -khtml-opacity: 1;
        opacity: 1;
    }
    
    0 讨论(0)
  • 2021-02-12 14:41

    Found this simple solution to change the position of the caret.

    //example of moving curser 20 pixels to the right
    input { 
        padding-left: 20px;
        padding-right: -20px;
    }
    
    0 讨论(0)
  • 2021-02-12 14:42

    Another way to change color is to configure bootstrap as you like on: http://getbootstrap.com/customize/

    For caret color change: Dropdowns -> @dropdown-caret-color

    then go to the bottom of the site and click "Compile & Download" to get your custom bootstrap version.

    But note @dropdown-caret-color is deprecated as of v3.1.0

    0 讨论(0)
  • 2021-02-12 14:43

    This works for Wordpress Bootstrap

    // Caret color
    .navbar .nav li.dropdown > .dropdown-toggle .caret {
        border-bottom-color: #FFFFFF;
        border-top-color: #FFFFFF;
    }
    
    0 讨论(0)
  • 2021-02-12 14:56

    There are two ways I have done this. If you want this to affect all carets on your site (probably not preferred) then you could override the caret css class in you:

    .caret{border-top:4px solid red;}
    

    Another option is to create a custom class and add it to the caret in your markup

    .red{border-top:4px solid red;}
    
    <div class="btn-group">
        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Action<span class="caret red"></span></button>
        <ul class="dropdown-menu" role="menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li class="divider"></li>
            <li><a href="#">Separated link</a></li>
        </ul>
    </div>
    

    The original JSFiddle has been updated http://jsfiddle.net/whoiskb/pE5mQ/

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