Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clickable button or glyphicon within list-group-item

Right now I am trying to insert a glyphicon or button within a list-group-item. What I want is that when the user clicks anywhere within the list-group-item, they are linked to a certain page, but when they click the glyphicon or button, they link to another page. Why I try to do this, it keeps putting the glyphicon or button outside of the list-group-items box. Why is this? How can I fix this?

Much appreciated.

Code:

<div class="list-group">
            <a href="my_django_url" class="list-group-item">
                            <a href="another_django_url"><span class="glyphicon some-glyphicon"></span></a>
            </a>

like image 770
steve-o Avatar asked Nov 23 '14 21:11

steve-o


3 Answers

here you go:

<div class="list-group">
    <li class="list-group-item">
        <a href="my_django_url">
           first link
        </a>
        <a href="another_django_url" class="icon">
            <span class="glyphicon glyphicon glyphicon-search"></span>
        </a>
    </li>
</div>

.icon {
    float: right;
}

fiddle: http://jsfiddle.net/9r14uuLw/

like image 58
ncosta Avatar answered Sep 23 '22 12:09

ncosta


Pardon the brevity (at work / slammed):

This is what I'll be going with for the rest of my project(s)...

<div class="list-group-item row" ng-repeat="item in list.items">
    <a class="col-xs-6 col-sm-8 col-md-10 col-lg-10 pull-left" href="#/lists/{{list.id}}/items/{{item.id}}"><h5>{{item.name}} ({{item.quantity}})</h5></a>
    <h5 class="col-xs-6 col-sm-4 col-md-2 col-lg-2 pull-right">
        <a class="pull-left" href="#/lists/{{list.id}}/items/{{item.id}}/edit" ng-show="list.name !== 'all-deleted-items'"><u>Edit</u></a>
        <a class="pull-right" href="" ng-click="removeItem(item, $event)" ng-show="list.name !== 'all-deleted-items'"><u>Remove Item</u></a>
    </h5>
</div>

This is working code from my project -- apologies for the crude Copy/Paste! The lower <h5> is simply for vertical alignment. The row class added to div.list-group-item is to take up full container width (optional).

#caveat:

Not the entire height is actionable as a link, but this may be a decent compromise.

Hope this helps!

like image 34
Cody Avatar answered Sep 22 '22 12:09

Cody


It sounds like you want the entire list-group-item to be a link, which is not accomplished by the answer provided. You can't have an <a> tag inside another <a> tag, so I think you need to use absolute positioning to accomplish what you are trying to do.

<div class="list-group-item" style="padding: 0;">
    <a href="#" style="display: block; padding: 10px 15px;">test</a>
    <a href="#" class="btn btn-sm btn-danger" style="position: absolute; top: 50%; right: 15px; margin-top: -15px;">hi</a>
</div>

That should be close to what you're after. I just added some inline styles to quickly show you how it can be done, but you'll probably want to come up with some more generic styles to re-use this easily.

like image 32
dvanderb Avatar answered Sep 24 '22 12:09

dvanderb