我正在尝试将徽标放在bootstrap导航栏中,但发出徽标比导航栏更大,所以我希望徽标能够响应并且很好地适应导航栏。我已经尝试过我能找到的每一个技巧,但图像仍然很大。请帮忙 这是主页:
<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;
}
}
答案 0 :(得分:1)
您可以进行媒体查询以更改其大小,例如:
@media(max-width: 768px;) {
.navbar-brand img { width: 100px; height: 75px; }
}
以适用于您定位的不同尺寸。
此外,你也可以获得一点点发烧友,而不是<img />
中的.navbar-brand
标记,你可以用这样的东西设置它的背景:
.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); }
}
答案 1 :(得分:1)
尝试添加此内容:
.navbar-brand {
padding: 5px;
}
.navbar-brand img {
max-height:100%;
height:100%;
width: auto;
}