使用Bootstrap时如何将文本与图像中心垂直对齐。

时间:2016-01-21 02:18:19

标签: html css twitter-bootstrap

我正在尝试为我的网站创建标题。我希望我的徽标位于左上角,导航栏位于窗口的右上角。我的问题是导航栏没有与我的徽标中心齐平。这是货物:

#logoHeader {
	float: left;
	vertical-align: middle;
}

ul {
	list-style: none;
	display: inline block;
	vertical-align: middle;
  
}

li {
	float: right; 
	padding: 10px;
	font-size: 22pt;
	display: inline-block;
}

.header .navContainer {
	height: 131px;
	vertical-align: middle;
}
<!DOCTYPE html> 
<html>

<head>
	<meta charset = "utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
	<link type= "text/css" rel="stylesheet" href="all.css"/>
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
	<script type = "text/javascript" src = "index.js"></script>
	
	<title>JM</title> 
</head>

<body> 

<div class ="container">

	<div class="row">
    	<div class="col-md-4 header">
    	<img id = "logoHeader" src="file:///Users/Jon/Desktop/JM.COM/images/bigJM.png"/> 
    	</div>
    	<div class="cold-md-8 navContainer">
        <ul class = "navBar">
        	<li>Home</li>
        	<li>Blog</li>
        	<li>Publications</li>
        	<li>Contact</li>
        </ul>
    	</div>
 
	</div>

</div>

</body>
</html>

2 个答案:

答案 0 :(得分:0)

遵循Bootstraps规则

http://getbootstrap.com/components/#navbar

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet"     href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"   integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
  </head>
  <body>
    <nav class="navbar navbar-default">
      <div class="container-fluid">
        <!-- 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="#bs-example-navbar-collapse-1" 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="bs-example-navbar-collapse-1">
          <ul class="nav navbar-nav navbar-right">
            <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
            <li><a href="#">Link</a></li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></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 role="separator" class="divider"></li>
                <li><a href="#">Separated link</a></li>
                <li role="separator" class="divider"></li>
                <li><a href="#">One more separated link</a></li>
              </ul>
            </li>
          </ul>
        </div><!-- /.navbar-collapse -->
      </div><!-- /.container-fluid -->
    </nav>
  <body>

</html>

    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

答案 1 :(得分:0)

bootstrap.min.css更改margin-topmargin-bottom到0px的olul选择器

实施例

ol, ul {
    margin-top: 0px;
    margin-bottom: 0px;
}

同样在你的问题填充中的css代码也是问题之一。设置10px的填充将导致顶部,底部,左侧和右侧的额外空间。

将其更改为

li {
    float: right; 
    /*padding: 10px;*/
  padding-left: 10px;
  padding-right: 10px;
    font-size: 22pt;
    display: inline-block;
}