Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 profile image in navbar

Tags:

How do I get the profile image (see picture) to be say 25/30px without distorting the navbar?

This is what I have now:

<li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
    <img src="http://placehold.it/18x18" class="profile-image img-circle"> Username <b class="caret"></b></a>
    <ul class="dropdown-menu">
        <li><a href="#"><i class="fa fa-cog"></i> Account</a></li>
        <li class="divider"></li>
        <li><a href="#"><i class="fa fa-sign-out"></i> Sign-out</a></li>
    </ul>
</li>

this is the result:

small image but no distortion

But if I change the size of the image to 30x30 this is what happens, how do I prevent the distortion of the navbar:

large image but a distorted navbar

I tried clearing the margin and paddings on the image but that had no effect.

Update: Here is a JSFiddle of the current code.

like image 547
Martijn Thomas Avatar asked Jun 02 '14 10:06

Martijn Thomas


2 Answers

after looking at the JSFiddle, I found out the problem is caused by the height of the image you use instead of the padding.

give the image a class, and make it float left, then use position:relative to tweak the position.

<li class="dropdown">
    <a href="#" class="dropdown-toggle profile-image" data-toggle="dropdown">
        <img src="http://placehold.it/30x30" class="img-circle special-img"> Test <b class="caret"></b></a>
                <ul class="dropdown-menu">
                    <li><a href="#"><i class="fa fa-cog"></i> Account</a></li>
                    <li class="divider"></li>
                    <li><a href="#"><i class="fa fa-sign-out"></i> Sign-out</a></li>
                </ul>
</li>

-

.special-img 
{
    position: relative;
    top: -5px;
    float: left;
    left: -5px;
}

My Fiddle here

like image 64
Kooki3 Avatar answered Sep 24 '22 23:09

Kooki3


You got it mostly right following what Kooki3 said, there's just more specificity in the Bootstrap stylesheet, so just change your .profile-image to .navbar-nav>li>a.profile-image

Editing your fiddle like this, the nav looks perfect to me:

.navbar-nav>li>a.profile-image {
    padding-top: 10px;
    padding-bottom: 10px;
}
like image 42
jme11 Avatar answered Sep 24 '22 23:09

jme11