我想将徽标居中。我能够通过定义填充和内容来居中,但问题是当我尝试在不同的显示器/分辨率上查看时,徽标会移动。
以下是代码:
/* Navigation */
.navbar {-moz-border-radius: 0;-webkit-border-radius: 0;border-radius: 0;margin-bottom: 0;}
.navbar .container {text-align: center; position: center; background-color: #fff; right:55px;}
.navbar-default {-moz-transition: all 0.3s ease-out;-o-transition: all 0.3s ease-out;-webkit-transition: all 0.3s ease-out;transition: all 0.3s ease-out;width: 100%;border: none;border-bottom: 0px solid #e7e7e7;background-color: #fff; }
.navbar-default .navbar-nav > li > a {color: #000;font-weight: normal;font-size: 15px; display: inline-block; padding-right: 23px; padding-left: 23px}
.navbar-default .navbar-nav > li > a:hover {background-color: transparent;color: #005FA6;}
.navbar-default .navbar-nav > .open > a,.navbar-default .navbar-nav > .open > a:hover,.navbar-default .navbar-nav > .open > a:focus {background-color: transparent;color: #005FA6;}
.navbar-default .navbar-nav .active > a,.navbar-default .navbar-nav .active > a:hover,.navbar-default .navbar-nav .active > a:focus {color: #005FA6;background-color: transparent;}
.navbar-default .navbar-toggle {margin: 10px 0 0 15px;}
.navbar-default .navbar-toggle,.navbar-default .navbar-toggle:hover,.navbar-default .navbar-toggle:focus {border: none;background: #f3f3f3;}
.navbar-default .navbar-toggle i {font-size: 31px;}
.navbar-default .navbar-collapse {float: right; border-top: none;padding-left: 0;padding-right: 0;}
.navbar-brand>img {padding: 5px; align: center;}

<nav class="navbar navbar-default">
<div class="container">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-navbar-collapse">
<span class="sr-only">Toggle Navigation</span>
<i class="fa fa-bars"></i>
</button>
<a href="index.php" class="navbar-brand">
<img src="img/corelogo.png" alt="" height="150" width="150">
</a>
</div>
</nav>
&#13;
答案 0 :(得分:2)
将您的徽标<img>
标记设为display:block
。然后给它左右边距auto
。
以下示例:
/* Navigation */
.navbar {
-moz-border-radius: 0;
-webkit-border-radius: 0;
border-radius: 0;
margin-bottom: 0;
}
.navbar .container {
text-align: center;
position: center;
background-color: #fff;
right: 55px;
}
.navbar-default {
-moz-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
-webkit-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
width: 100%;
border: none;
border-bottom: 0px solid #e7e7e7;
background-color: #fff;
}
.navbar-default .navbar-nav>li>a {
color: #000;
font-weight: normal;
font-size: 15px;
display: inline-block;
padding-right: 23px;
padding-left: 23px
}
.navbar-default .navbar-nav>li>a:hover {
background-color: transparent;
color: #005FA6;
}
.navbar-default .navbar-nav>.open>a,
.navbar-default .navbar-nav>.open>a:hover,
.navbar-default .navbar-nav>.open>a:focus {
background-color: transparent;
color: #005FA6;
}
.navbar-default .navbar-nav .active>a,
.navbar-default .navbar-nav .active>a:hover,
.navbar-default .navbar-nav .active>a:focus {
color: #005FA6;
background-color: transparent;
}
.navbar-default .navbar-toggle {
margin: 10px 0 0 0;
}
.navbar-default .navbar-toggle,
.navbar-default .navbar-toggle:hover,
.navbar-default .navbar-toggle:focus {
border: none;
background: #f3f3f3;
}
.navbar-default .navbar-toggle i {
font-size: 31px;
}
.navbar-default .navbar-collapse {
float: right;
border-top: none;
padding-left: 0;
padding-right: 0;
}
.navbar-brand img {
border:1px solid black;
width:150px;
height:150px;
display:block;
margin: 15px auto 0px auto;
}
&#13;
<nav class="navbar navbar-default">
<div class="container">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-navbar-collapse">
<span class="sr-only">Toggle Navigation</span>
<i class="fa fa-bars"></i>
</button>
<a href="index.php" class="navbar-brand">
<img src="img/corelogo.png" alt="" height="150" width="150">
</a>
</div>
</nav>
&#13;
答案 1 :(得分:0)
您只需添加display: block;
,然后使用margin: 0 auto;
以下是您的代码:.navbar-brand > img { display: block; margin: 0 auto;}
<style>
.navbar {-moz-border-radius: 0;-webkit-border-radius: 0;border-radius: 0;margin-bottom: 0;}
.navbar .container {text-align: center; position: center; background-color: #fff; right:55px;}
.navbar-default {-moz-transition: all 0.3s ease-out;-o-transition: all 0.3s ease-out;-webkit-transition: all 0.3s ease-out;transition: all 0.3s ease-out;width: 100%;border: none;border-bottom: 0px solid #e7e7e7;background-color: #fff; }
.navbar-default .navbar-nav > li > a {color: #000;font-weight: normal;font-size: 15px; display: inline-block; padding-right: 23px; padding-left: 23px}
.navbar-default .navbar-nav > li > a:hover {background-color: transparent;color: #005FA6;}
.navbar-default .navbar-nav > .open > a,.navbar-default .navbar-nav > .open > a:hover,.navbar-default .navbar-nav > .open > a:focus {background-color: transparent;color: #005FA6;}
.navbar-default .navbar-nav .active > a,.navbar-default .navbar-nav .active > a:hover,.navbar-default .navbar-nav .active > a:focus {color: #005FA6;background-color: transparent;}
.navbar-default .navbar-toggle {margin: 10px 0 0;}
.navbar-default .navbar-toggle,.navbar-default .navbar-toggle:hover,.navbar-default .navbar-toggle:focus {border: none;background: #f3f3f3;}
.navbar-default .navbar-toggle i {font-size: 31px;}
.navbar-default .navbar-collapse {float: right; border-top: none;padding-left: 0;padding-right: 0;}
.navbar-brand > img { display: block; margin: 0 auto;}
</style>
<nav class="navbar navbar-default">
<div class="container">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-navbar-collapse">
<span class="sr-only">Toggle Navigation</span>
<i class="fa fa-bars"></i>
</button>
<a href="index.php" class="navbar-brand">
<img class="my-image" src="img/corelogo.png" alt="" height="150" width="150">
</a>
</div>
</nav>