Reputation: 397
I am beginner in ASP.NET MVC and in default project template I'm trying to add a logo in navbar with the company name, I have successfully added logo with company name. But, logo and company name both are not in the same line. I am trying to inline it. I spent lots of time but I could not find the solution. My output & code is given below.
Output:
Code:
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="/Home/Index" class="navbar-brand"> <img src="~/Content/images/logo.png" alt="Company logo" height="100"/> </a>
@Html.ActionLink("Contact Lenses", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
@Html.Partial("_LoginPartial")
</div>
</div>
</div>
Please tell me, how can I inline it?
Upvotes: 0
Views: 2251
Reputation: 1562
You just need to change the height and margin-top of navbar.
I added a class name companyName to your Action link and added css margin-top
.
Same margin-top
value for navbar-nav
class too.
@Html.ActionLink("Contact Lenses", "Index", "Home", new { area = "" }, new {
@class = "navbar-brand companyName"})
.companyName, .navbar-nav{
margin-top: 15px !important;
}
I changed the logo height to 50.
Note: I checked with some other logo image. I think that is bit larger than your logo size. That's why I changed height to 50, but you can keep it as your wish, then you need to set the margin-top value for companyName
and navbar-nav
accordingly. Then set height = auto
to anchor tag, like bellow.
<a href="/Home/Index" class="navbar-brand myLogo">
<img src="~/Content/images/logo.png" alt="Company logo" height="50"/>
</a>
.myLogo{
height:auto;
}
I tested this code. Working as expected. Hope it helps :)
Upvotes: 1