[英]Centering an Image in a twitter bootstrap navbar
Here is my live site: http://ancient-badlands-4040.herokuapp.com/ 这是我的现场网站: http : //ancient-badlands-4040.herokuapp.com/
I am trying to center my image and also have the links align vertically with the image. 我试图使我的图像居中,并使链接与图像垂直对齐。
I got a lot of help with this so far after reading this post Twitter Bootstrap - centering brand logo in navbar 到目前为止,在阅读了这篇文章Twitter Bootstrap - 导航栏中的中心品牌标识后,我得到了很多帮助
I was successful earlier centering my image by adjusting my "brand" class (I set the width to 28%). 通过调整我的“品牌”类(我将宽度设置为28%),我之前成功地使我的图像居中。 Unfortunately, I had to adjust the "navbar" class's width as well, after adjusting the width it changed the position of my logo. 不幸的是,我不得不调整“navbar”类的宽度,调整宽度后它改变了我的徽标的位置。
I changed my code to the following below, I am trying to center my image and have the links line up evenly with my center image. 我将我的代码更改为以下内容,我正在尝试将图像居中,并使链接与我的中心图像均匀排列。
Any help would be appreciated, thanks! 任何帮助将不胜感激,谢谢! :) :)
HTML: **Updated divs and ul classes HTML:**更新了div和ul类
<div class="navbar navbar-fixed-top">
<div class="navbar-inner ">
<div class="container-fluid">
<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>
<div class="nav-collapse collapse">
<ul class="nav pull-right">
<li><a>CODEY</a>
</li>
<li> <a>CODEY</a></li>
</ul>
<ul class="nav pull-left">
<li><a>CODEY</a></li>
<li><a>CODEY</a></li>
<li><a>CODEY</a></li>
</ul>
<a class="brand"></a>
<%= image_tag 'ctclogonewnobg.png', alt: 'logo' %>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
CSS: CSS:
$navbarLinkColor: #90fce8;
$navbarBackground: #ff3600;
$navbarBackgroundHighlight: #ff3600;
$navbarText: Archivo Black, sans-serif;
@import url(http://fonts.googleapis.com/css?family=Archivo+Black);
@import 'bootstrap';
body {
background: url('escheresque_@2X.png');
}
@import 'bootstrap-responsive';
.navbar-inner {
@include box-shadow(none !important);
border: 0;
width: 100%%;
margin: auto;
}
.navbar .brand {
margin-left: auto;
margin-right: auto;
width: 20px;
float: none;
}
Here are a couple examples for you in a CodePen - http://codepen.io/michaellee/pen/nLmJa 以下是CodePen中的几个示例 - http://codepen.io/michaellee/pen/nLmJa
Basically the first example uses display: inline-block; 基本上第一个例子使用display:inline-block; to align everything in a line and vertical-align: middle; 对齐行中的所有内容和vertical-align:middle; the blocks. 块。
The second example is more like yours where you can float the nav's to the left and right and use padding to create a vertically, centered look and feel. 第二个例子更像是你的,你可以向左和向右浮动导航,并使用填充创建一个垂直,居中的外观和感觉。
HTML HTML
<header>
<ul class="nav-left">
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
<span class="logo">Logo!</span>
<ul class="nav-right">
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
</header>
<br />
<header class="second">
<ul class="nav-left">
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
<span class="logo">Logo!</span>
<ul class="nav-right">
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
</header>
CSS CSS
header{
width: 100%;
text-align: center;
background: #e63100;
display:block;
overflow: hidden;
}
ul{
list-style: none;
display: inline-block;
vertical-align: middle;
margin: 0;
padding: 0;
li{
display: inline-block;
}
}
.logo{
font-size: 30px;
vertical-align: middle;
margin: 0 40px;
}
.second{
.nav-left{
float: left;
}
ul{
padding: 30px 0;
}
.nav-right{
float: right;
}
.logo{
padding: 20px 0;
display: inline-block;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.