我正在使用Twitter Bootstrap,并且试图使用户的个人资料图片在导航栏中出现在其用户名旁边。

这是我的代码。但是,发生的情况是图片最终平齐到屏幕顶部。我不知道Twitter Bootstrap CSS是否有办法使其居中。任何建议将不胜感激。

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<div class="navbar navbar-inverse navbar-fixed-top">
    <div class="navbar-inner">
        <div class="container">
            <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </a>
            <a class="brand" href="#">Codename: Success</a>
            <div class="nav-collapse collapse">
                <ul class="nav">
                    <li class="active"><a href="#">Home</a></li>
                    <li><a href="#about">About</a></li>
                    <li><a href="#contact">Contact</a></li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            <li><a href="#">Action</a></li>
                            <li><a href="#">Another action</a></li>
                            <li><a href="#">Something else here</a></li>
                            <li class="divider"></li>
                            <li class="nav-header">Nav header</li>
                            <li><a href="#">Separated link</a></li>
                            <li><a href="#">One more separated link</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
            <c:choose>
                <c:when test="${not empty pageContext.request.userPrincipal.name}">
                    <div id="userHeaderProfile" class="navbar-text pull-right">
                        <p>${pageContext.request.userPrincipal.name}</p>
                    </div>
                    <div class="pull-right"><img src="http://placehold.it/30x30" alt="30x30" /></div>
                </c:when>
                <c:otherwise>
                    <form method="post" class="navbar-form pull-right" action="<c:url value='/j_spring_security_check'/>">
                        <input id="username" name="j_username" class="span2" type="text" placeholder="Email">
                        <input id="password" name="j_password" class="span2" type="password" placeholder="Password">
                        <button type="submit" class="btn">Sign in</button>
                    </form>
                </c:otherwise>
            </c:choose>
            <!--/.nav-collapse -->
        </div>
    </div>
</div>

最佳答案

这是我对导航栏中用户名位置所做的一切

的HTML

<div class="pull-right navbar-text">
  <img src="http://placehold.it/30x30">
  Chuck Norris
</div>


的CSS

.navbar-text img {
max-height:30px;
宽度:自动;
垂直对齐:中间;
}

07-26 01:07