[英]how to put logo in bootstrap navbar
我正在嘗試將徽標放入引導導航欄中,但問題是徽標大於導航欄,因此我希望徽標能夠響應並很好地適合於導航欄中。 我嘗試了所有可以找到的技巧,但圖像仍然很大。 請幫助這里是母版頁:
<body>
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<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="#">
<%--<img src="http://placehold.it/150x50&text=Logo" alt=""/>--%>
<img src="img/chs.jpg"" alt=""/>
</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">
<li>
<a href="#">About</a>
</li>
<li>
<a href="#">Services</a>
</li>
<li>
<a href="#">Contact</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<!-- Page Content -->
<div class="container">
<div class="row">
<div class="col-lg-12">
<h1>Logo Nav by Start Bootstrap</h1>
<p>Note: You may need to adjust some CSS based on the size of your logo. The default logo size is 150x50 pixels.</p>
</div>
</div>
</div>
<!-- /.container -->
<!-- jQuery -->
<script src="Scripts/jquery-2.1.3.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="Scripts/bootstrap.min.js"></script>
</body>
我的css文件
body {
padding-top: 70px; /* Required padding for .navbar-fixed-top. Change if height of navigation changes. */
}
.navbar-fixed-top .nav {
padding: 15px 0;
}
.navbar-fixed-top .navbar-brand {
padding: 0 15px;
}
@media(min-width:768px) {
body {
padding-top: 100px; /* Required padding for .navbar-fixed-top. Change if height of navigation changes. */
}
.navbar-fixed-top .navbar-brand {
padding: 15px 0;
}
}
您可以進行媒體查詢以更改其大小,例如:
@media(max-width: 768px;) {
.navbar-brand img { width: 100px; height: 75px; }
}
等等,以您要定位的不同尺寸為准。
此外,您還可以稍微想一點點,而不是在.navbar-brand
添加<img />
標簽,而可以通過以下方式設置背景:
.navbar-brand img { width: 200px; height: 125px; background-image: url(../img/my-logo.png); }
這樣您就可以通過媒體查詢來更改實際的圖片,例如:
@media(max-width: 768px;) {
.navbar-brand img { width: 100px; height: 75px; background-image: url(../img/my-logo-small.png); }
}
嘗試添加以下內容:
.navbar-brand {
padding: 5px;
}
.navbar-brand img {
max-height:100%;
height:100%;
width: auto;
}
這是演示: https : //jsfiddle.net/6L65j2sv/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.