Skip to content

Instantly share code, notes, and snippets.

@matthewhartstonge
Last active January 31, 2021 22:16
Show Gist options
  • Select an option

  • Save matthewhartstonge/1d2aaee2165b67842868 to your computer and use it in GitHub Desktop.

Select an option

Save matthewhartstonge/1d2aaee2165b67842868 to your computer and use it in GitHub Desktop.
Bootstrap 3 Navbar Profile CSS with HTML Example
/* Bootstrap 3 Navbar Profile Picture CSS
*
* The CSS for profile pictures in the navbar has always annoyed me,
* so here's my fix that appears to have the least hoops.
*
* Production use:
* >Add a div with the specified class.
* >Using JS, change the profile picture CSS URL as needed.
*
* HTML example:
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#nav-collapse" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="nav-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Link<span class="sr-only">(current)</span></a></li>
<li><a href="#">Another Link</a></li>
</ul>
<ul class="nav navbar-nav pull-right">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<!-- The Profile picture inserted via div class below, with shaping provided by Bootstrap -->
<div class="img-rounded profile-img"></div>
User Name <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>
<a href="#">Settings</a>
</li>
<li role="separator" class="divider"></li>
<li>
<a href="#">Log out</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
*
* Written By: Matt Hartstonge
* Date Written: 09/07/2015
*/
.profile-img{
margin-top: -5px;
margin-right: 5px;
float: left;
background: url(example.jpg) 50% 50% no-repeat; /* 50% 50% centers image in div */
background-size: auto 100%; /* Interchange this value depending on prefering width vs. height */
width: 30px;
height: 30px;
}
@iampaone

iampaone commented Dec 8, 2017

Copy link
Copy Markdown

is this or bootstrap 3??? or 4???

@zepochs

zepochs commented Dec 12, 2017

Copy link
Copy Markdown

For bootstrap 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment