5
votes

I have a navbar and I have a caret next to dropdown menu.

In current code, if user clicks Operations text or caret, dropdown menu is opened. But I need this:

  • If user clicks Operations link, I want user to go to my /operations/ page.
  • If user clicks to the caret, dropdown menu will be visible. If user click one of the elements of dropdown menu, user will be redirected to related page.

Fiddle: http://jsfiddle.net/mavent/UtDqm/2/

<div class="navbar navbar-inverse">
  <li class="dropdown" id="myTools">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#myTools">
        Operations
        <b class="caret"></b>
    </a>
    <ul class="dropdown-menu">
        <li><a href="/mypage1/">MyPage 1</a></li>
        <li><a href="/mypage2/">MyPage 2</a></li>
    </ul>
  </li>  
</div>   

In Twitter bootstrap documentation it is noted how to create split button dropdowns here. I don't want to use buttons. Is it possible to have split behaviour without using buttons. Just with links?

2
Why don't you just wrap the caret in the dropdown-toggle and add a normal href to the operations text? See here - Joshua M
@JoshuaM same behaviour like Stevie's answer. This works but the caret goes to the next line in navbar. image link - trante
Do you have the a style set to be display: block? Thats all I can think of, as it works fine for me. - Joshua M
I mean do you have somewhere in your stylesheet a style defined like a { display: block }? This could be pushing the caret down onto the next like as the two <a> tags round the text and caret are being forced onto new lines. Is there anywhere I could view your working code? - Joshua M
Updated my answer, the bootstrap style for the <a> tags are display:block as Joshua mentioned. If you override them to display:inline-block; it works. - Steve Valliere

2 Answers

9
votes

Couldn't you just split the Operations link into a new <a> tag?

<div class="navbar navbar-inverse">
  <li class="dropdown" id="myTools">
    <a href="/operations/" style="display:inline-block;padding-right:0px;">Operations</a>
    <a class="dropdown-toggle" data-toggle="dropdown" href="#myTools"  style="display:inline-block;padding-left:0px;">
      <b class="caret"></b>
    </a>
    <ul class="dropdown-menu">
      <li><a href="/mypage1/">MyPage 1</a></li>
      <li><a href="/mypage2/">MyPage 2</a></li>
    </ul>
  </li>  
</div>
3
votes

Are you looking for something like this?

<div class="btn-group">
    <a href="http://google.com" target="_blank" class="btn btn-link">Action</a>
   <a href="#" class="btn btn-link dropdown-toggle" data-toggle="dropdown">
    <span class="caret"></span>
  </a>
  <ul class="dropdown-menu">
        <li><a href="/mypage1/">MyPage 1</a></li>
        <li><a href="/mypage2/">MyPage 2</a></li>
    </ul>
</div>

http://jsfiddle.net/UtDqm/6/