Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Good morning all

I am trying to create a Bootstrap navigation bar which displays a .jpg file as a background. The code is as follows:
    <header class="row container-fluid img-responsive" style="margin-bottom: 0; margin-right: 0; height: 200px; background-color: #ffffbf;
            background-image: url(/Content/Graphics/ClubHeader.jpg); background-position: bottom left; background-repeat: no-repeat;">
    <nav class=" navbar col-xs-12 col-sm-10 img-responsive" role="navigation">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
        <div class="collapse navbar-collapse">
            <ul class="nav navbar-nav pull-right" style="margin-removed 0; margin-removed 0;">
                <li>@Html.ActionLink("About Us", "About", "Home")</li>
                <li>@Html.ActionLink("Contact Us", "Contact", "Home")</li>
                <li>@Html.ActionLink("Privacy Policy", "Privacy", "Home")</li>
                <li>@Html.ActionLink("Useful Links", "Links", "Home")</li>
            </ul>
        </div>
    </nav>
    <div class="hidden-xs col-sm-2">
        @Html.Partial("_LoginPartial")
    </div>
</header>

The .jpg is size 200x570 and contains the Club badge and name.

When I run the webpage, the navigation bar collapses but the 3-bar "hamburger" icon is not displayed. It is there because the pointer changes to a hand and the menu appears as a dropdown if you then press the left mouse button.

The other problem is that the Club logo image does not shrink when the width is too small to display it full size. It starts truncating the right hand edge. Only when it gets below a width of 380 pixels does it start becoming responsive.

What bootstrap css have I forgotten to specify?
Posted

1 solution

The lines in the "hamburger" menu don't have a default colour set.

You could add either the navbar-default or navbar-inverse class to your navbar. However, this would also set the background and border colour for the navbar itself, meaning that your image wouldn't show through.

Alternatively, you could set a default background colour for the icon bar:
CSS
.navbar .navbar-toggle .icon-bar 
{
    background-color: #888;
}

There will be other styles from navbar-default which you might need to copy, depending on how you want the navbar to look.

To get the background image to scale, you'll need to use the background-size property[^] - set it to either contain or cover, depending on how you want the image to scale.

NB: This property is not supported in IE8 or earlier[^].

Example: https://jsfiddle.net/6pvzdgut/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900