3

How do I fix these 3 issues facing my bootstrap navigation bar:

  • Menu cannot collapse properly when resized (window made smaller)
  • Have the icons beside the menu links instead of below them
  • Have the sign up/login button link to another page when the window is resized

Here is a demo:

https://jsfiddle.net/whywymam/zpdpsuLn/

HTML Code:

<div class="container">

      <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">

          <navbar>

              <div class="upperRow">

               <div class="navbar-header">
                    <a href="#" class="brand navbar-brand"> <img src="image/logo.png" class="img-responsive"></a>
               </div>

               <div id="btnTopInline">

                   <ul class="nav navbar-nav navbar-right imgicon hidden-xs">

                       <li>
                         <div class="indivColl">
                            <a href="signupLogin.php">
                               <img src="image/jobseekerlogo.png" class="indi">
                               <p class="indit">Job Seeker</p>
                            </a>
                         </div>
                       </li>

                       <li>
                         <div id="empColl">
                            <a href="signupLoginEmp.php">
                               <img src="image/employerlogo.png" class="emp">
                               <p class="empt">Employer</p>
                            </a>
                         </div>
                       </li>

                   </ul>

               </div>

               <!--                for tablet and mobile view-->
                <button type="button" class="btn btn-login pull-right visible-xs">
                    <a href="signupLoginEmp.php">
                        Employer<br>Log In
                    </a>
                </button>

                <button type="button" class="btn btn-login pull-right visible-xs">
                    <a href="signupLogin.php">
                        Job Seeker<br>Log In
                    </a>
                </button>

              </div>

            <div class="middleRow">

                <div class="navbar-inner navbar-default navbar-static-top navcolor">

                          <div class="navbar-header ">

                              <!--button to appear when display is on mobile device-->
                              <button type="button" class="navbar-toggle pull-right" data-toggle="collapse" data-target=".nav-collapse">
                                  <span class="sr-only">Toggle navigation</span>
                                  <span class="icon-bar"></span>
                                  <span class="icon-bar"></span>
                                  <span class="icon-bar"></span>
                              </button>

                          </div>

                          <div class="nav-collapse collapse-in" id="nav-collapse">

                              <ul class="nav  navbar-nav center-block">
                                <li><a href="home.php">Home<img src="image/home.png" width="75" height="65" alt="" title="" /></a></li>
                                <li><a href="about.php">About<img src="image/about.png" width="75" height="65" alt="" title="" /></a></li>
                                <li><a href="pyw.php">Prove Job<img src="image/PYW.png" width="75" height="65" alt="" title="" /></a></li>
                                <li><a href="#">Job<img src="image/jobs.png" width="75" height="65" alt="" title="" /></a></li>
                                <li><a href="rescources.php">Resources<img src="image/resource.png" width="75" height="65" alt="" title="" /></a></li>
                             </ul>

                          </div>


                    </div> <!-- end inner navbar -->

            </div> <!-- end middle row -->

          </navbar>

      </div> <!-- end col-lg-12 col-md-12 col-sm-12 col-xs-12 -->

  </div><!-- end container -->

CSS:

.img-responsive {
max-width: 60%;
margin-bottom: 15%;
padding-top: -3%;
}
.imgicon {
padding-left: 50%;
margin-top: -2%;
}

.middleRow{
padding-top: 10%;
margin-top: 5%;
}

.navcolor{
background-color: transparent;
}

.navbar-default {
margin-top: 3%;
}

.navbar-nav {
float:none;
margin: 0 auto;
display: table;
table-layout: fixed;
text-align: center;
}

#btnTopInline{
display: inline-block;
float: right;
clear: none;
}

@media(min-width:768px) {
  .nav-collapse{
        display: inline;
  }
  }

Thank you in advance :)

1
  • in your demo, everything seems fixed....? Commented Jun 25, 2015 at 4:34

2 Answers 2

2

Here is code i have made some modification in html and css

for the toggal button to work use data-target=".nav-collapse" insted of data-target=".navbar-collapse"

for icons beside the menu links add img tag inside ancor tag.

below are changes

<body>
         <div class="navbar">
            <div class="navbar-inner">
               <div class="container">
                  <div class="navbar-header">
                     <a href="#" class="brand navbar-brand"> <img src="image/logo.png" class="img-responsive"></a>
                  </div>
                  <ul class="nav navbar-nav navbar-right imgicon hidden-xs">
                     <div id="indivColl">
                        <a href="signupLogin.php">
                           <img src="image/jobseekerlogo.png" class="indi">
                           <p class="indit">Job Seeker</p>
                        </a>
                     </div>
                     <div id="empColl">
                        <a href="signupLoginEmp.php">
                           <img src="image/employerlogo.png" class="emp">
                           <p class="empt">Employer</p>
                        </a>
                     </div>
                  </ul>
                  <!--                for tablet and mobile view-->
                  <button type="submit" id="btn-login-header" class="btn btn-login pull-right visible-xs mobile-login" 
                     id="header-mobile-login-button" data-target="#indivColl">
                  Employer<br>Log In
                  </button>
                  <button type="submit" id="btn-login-header" class="btn btn-login pull-right visible-xs mobile-login" 
                     id="header-mobile-login-button" data-target="#empColl">
                  Job Seeker<br>Log In
                  </button>

                  <button type="button" class="navbar-toggle btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                  <span class="icon-bar">Toggle navigation</span>
                  <span class="icon-bar"></span>
                  <span class="icon-bar"></span>
                  </button>

                  <div class="nav-collapse collapse in" id="navbar-collapse">
                     <ul class="nav navbar-nav">
                        <li><a href="home.php">Home<img src="image/home.png" width="75" height="65" alt="" title="" /></a></li>
                        <li><a href="about.php">About<img src="image/about.png" width="75" height="65" alt="" title="" /></a></li>
                        <li><a href="pyw.php">Prove Your Worth<img src="image/PYW.png" width="75" height="65" alt="" title="" /></a></li>
                        <li><a href="#">Job<img src="image/jobs.png" width="75" height="65" alt="" title="" /></a></li>
                        <li><a href="rescources.php">Resources<img src="image/resource.png" width="75" height="65" alt="" title="" /></a></li>
                     </ul>
                  </div>
               </div>
            </div>
         </div>
   </body>

add this in css

@media(min-width:768px) {
      .nav-collapse{
            display: block;
      }
 }
Sign up to request clarification or add additional context in comments.

1 Comment

How do I ensure that the navigation menu is at the center of the page at all screen sizes? I've tried using center-block and nav-justified but it doesn't work.
0

First: For the responsive layout work the bootstrap need to work with rows and columns. You need to put the navbar inside.

<div class="row">
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
         <navbar>
         </navbar>
    </div>
</div>

Second: I don't test, but i think which inside the li of navbar you need to create a div with class containing text-align: center; or put this class in the li. Inside the div put the text and icon, each one with a class, containing float: left and clear: both.

<ul class="nav navbar-nav navbar-right imgicon hidden-xs">
            <div id="indivColl">
            <a href="signupLogin.php"><img src="image/jobseekerlogo.png" class="indi"><p class="indit">Job Seeker</p></a>
            </div>

            <div id="empColl">
            <a href="signupLoginEmp.php"><img src="image/employerlogo.png" class="emp"><p class="empt">Employer</p></a>
            </div>
        </ul>

Above you need to put each div inside a li. Insert the class in the img and trade the p tag to a span tag, after, add the same class to the span. The example is a supposition, i don't test but you can search more about the float and clear in www.w3cschools.com

The logic of navbar in your code is totaly wrong. You have a navbar inside a navbar with two containers. You need to review the concepts of bootstrap, html and css dude! Compare this with yours:

    <div class="navbar navbar-default navbar-static-top navcolor">

<div class="navbar-header">
  <a href="#" class="navbar-brand"> <img src="image/logo.png" class="img-responsive"></a>
</div>

<!-- for tablet and mobile view-->
<button type="submit" id="btn-login-header" class="btn btn-login pull-right navbar-btn visible-xs mobile-login" id="header-mobile-login-button" data-target="#indivColl">  Job Seeker Log In </button>
<button type="submit" id="btn-login-header" class="btn btn-login pull-right navbar-btn visible-xs mobile-login" id="header-mobile-login-button" data-target="#empColl"> Employer Log In </button>

<div class="navbar-header">
  <!--button to appear when display is on mobile device-->
  <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>
  </button>
</div>

<div class="collapse navbar-collapse" id="navbar-collapse">
  <ul class="nav navbar-nav">
    <li><a href="home.php">Home</a><img src="image/home.png" width="75" height="65" alt="" title="" /></li>
    <li><a href="about.php">About</a><img src="image/about.png" width="75" height="65" alt="" title="" /></li>
    <li><a href="pyw.php">Prove Your Worth</a><img src="image/PYW.png" width="75" height="65" alt="" title="" /></li>
    <li><a href="#">Job</a><img src="image/jobs.png" width="75" height="65" alt="" title="" /></li>
    <li><a href="rescources.php">Resources</a><img src="image/resource.png" width="75" height="65" alt="" title="" /></li>
    <li class="imgicon hidden-xs">
      <div id="indivColl">
        <a href="signupLogin.php"><img src="image/jobseekerlogo.png" class="indi"><p class="indit">Job Seeker</p></a>
      </div>
    </li>
    <li class="imgicon hidden-xs">
      <div id="empColl">
        <a href="signupLoginEmp.php"><img src="image/employerlogo.png" class="emp"><p class="empt">Employer</p></a>
      </div>
    </li>
  </ul>
</div>

I doesnt enter in details with css or the completely bootstrap rules but i think this code can useful for you. And doesnt forgot the classes with float and clear ^^

This will be a way to do. Bye, like my answer if served !

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.