How to change the bootstrap caret pointing positio

2020-04-19 06:52发布

问题:

Within bootstrap the caret is always pointing down. I would like it to point to the right when when the menu is closed. See demo.

Demo: http://jsfiddle.net/Maty2/

HTML

<div class="functionbox funtog"> <a class="btn dropdown-toggle fleft" data-toggle="collapse" data-target="#demo-1" href="#"><span class="caret"></span></a>
        <h3>Recent</h3>
      </div>
      <div id="demo-1" class="collapse in">
        <div class="whitebox">
          <div id="myprojs">Hide this</div>
    </div>
</div>

CSS

.whitebox { padding: 20px; border-top: 1px dotted #b3b3b3; border-left: 1px dotted #b3b3b3; color: #444; background-color: white; position: relative; } 
.functionbox .btn { border: 2px solid #888; background: none; padding: 4px; margin: 0; height: 10px; }
.functionbox .btn .caret { margin: 2px; border-top: 4px solid #888; }
.functionbox { position: relative; }
.functionbox h3 { font-size: 1.4em; border-bottom: 3px solid #F2F2F2; }
.functionbox h2 { font-size: 1.8em; border-bottom: 3px solid #F2F2F2; }
.dropdown-menu { mid-width: 250px; }
.funtog .fleft { float: left; border: none; margin: 10px 10px 0 0; }
.funtog h3 { border-bottom: 1px dotted #b3b3b3; }

​JS

<script src="js/jquery.js"></script> 
<script src="js/bootstrap-dropdown.js"></script> 
<script src="js/bootstrap-button.js"></script> 
<script src="js/bootstrap-collapse.js"></script> 

I am not sure what I need to change in order to add this functionality. Does anyone have a suggestion? or possibly a solution?

Thanks

回答1:

After some discussion with a friend, we came up with adding this class:

.btn.collapsed > .caret {border-left: 4px solid #888; border-right: 0; border-top: 4px solid transparent; border-bottom: 4px solid transparent;}

Though we weren't able so solve the # from being added to the end of the URL. If anyone knows of a suggestion, that would be great.



回答2:

Simple:

<span class="dropup">
    <span class="caret"></span>
</span>


回答3:

  1. If your element starts out collapsed, make sure to add the class explicitly

    <a class="btn dropdown-toggle fleft collapsed" data-toggle="collapse" data-target="#demo-1" href="#"><span class="caret"></span></a>
    
  2. Use this CSS

    // open state - points up
    .functionbox .caret {
      border-top-width: 0;
      border-bottom-width: 5px;
      border-bottom-style: solid;
    }
    
    // collapsed state - points down
    .functionbox .collapsed .caret {
      border-top-width: 5px;
      border-bottom-width: 0;
    }