Responsive navigator splits into multiple tables

I have developed a site, and when I resize the browser window or use the tools that Firefox makes responsive, I don't see the navigation disruption and I don't have my own tablet, but have a few friends and they say the navigation bar is not showing correctly.

Navigation bar li's should be floating right and padded

I don't understand what I am doing wrong!

This site

Edited:

The navigation bar item should float to the right. Apple users say that when they open the site, it opens perfectly. But once they scroll down and back up, the li elements are not right-aligned but come in between them.

+3


source to share


5 answers


I think @khilley made a particularly relevant information about using Bootstrap standard markup and inline javascript components. Here are some reasons why:

  • Your current approach is using duplicate markup (for your menu). It is not DRY or affordable and it takes more effort to do it.
  • If you don't need to write your own javascript, you save development and testing time and a couple of bytes of download for your users.
  • Twitter Bootstrap is used on millions of websites, so it is tested daily by millions of people on millions of different device / OS / resolution combinations around the world. When you use standard markup and javascript component plugins, you have the advantage of knowing that it will just work.

What's more, you can easily reproduce all of your navigation behavior with just some styling, including using built-in affix markup to handle changes in your navbar. Pretty sweet!

DEMO

Several changes have been made to your markup and css. You can remove your custom javascript entirely, except for one click handler that you use to scroll to different sections.

Replace all navigation styles and markup as follows:

HTML:



<nav class="navbar nav-custom navbar-fixed-top" data-spy="affix" data-offset-top="80" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="glyphicon glyphicon-th-list"></span>
            </button>
            <span class="rc">RC</span>
        </div>
        <div class="collapse navbar-collapse">
            <ul class="nav navbar-nav navbar-right">
                <li class="active">
                    <a href="#home">Home</a>
                </li>
                <li>
                    <a href="#design">Design</a>
                </li>
                <li>
                    <a href="#develop">Develop</a>
                </li>
                <li>
                    <a href="#contact">Contact</a>
                </li>                
            </ul>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>

      

CSS

.nav-custom {
    width: 100%;
    height: 80px;
    z-index: 999;
    padding: 25px;
    background-color: #f87f73;
    border-bottom: 1px solid rgba(0, 0, 0, 0.18);
    font-size: 150%;
    color: #fff;
    -webkit-transition: all .35s ease;
    -o-transition: all .35s ease;
    transition: all .35s ease;
}
.nav-custom.affix {
    width: 100%;
    background-color: rgba(255, 255, 255, 1);
    color: #f87f73;
    height: 60px;
    padding: 14px;
    -webkit-transition: all .35s ease;
    -o-transition: all .35s ease;
    transition: all .35s ease;
}
.nav-custom .rc {
    background-color: #fff;
    color: #f87f73;
    padding: 5px;
    border-radius: 50% 0% 50% 0%;
    float: none;
}
.nav-custom.affix .rc {
    background-color: #f87f73;
    color: #fff;
}
.nav-custom.affix .navbar-collapse {
    top: 60px;
}
.nav>li>a:hover, .nav>li>a:focus {
    background-color: transparent;
}
button{
    outline: none;
}
.navbar-toggle {
    padding: 0;
    margin: 0;
}
@media (min-width: 768px) { 
    .nav-custom a::before,
    .nav-custom a::after {
        display: inline-block;
        opacity: 0;
        -webkit-transition: -webkit-transform 0.3s, opacity 0.2s;
        -moz-transition: -moz-transform 0.3s, opacity 0.2s;
        transition: transform 0.3s, opacity 0.2s;
    }
    .nav-custom a::before {
        margin-right: 10px;
        content: '[';
        -webkit-transform: translateX(20px);
        -moz-transform: translateX(20px);
        transform: translateX(20px);
    }
    .nav-custom a::after {
        margin-left: 10px;
        content: ']';
        -webkit-transform: translateX(-20px);
        -moz-transform: translateX(-20px);
        transform: translateX(-20px);
    }
    .nav-custom a:hover::before,
    .nav-custom a:hover::after,
    .nav-custom a:focus::before,
    .nav-custom a:focus::after {
        opacity: 1;
        -webkit-transform: translateX(0px);
        -moz-transform: translateX(0px);
        transform: translateX(0px);
    }
    .nav-custom a:link, .nav-custom a:visited, .nav-custom a:hover, .nav-custom a:active {
        text-decoration: none;
        color: #fff;
        outline: none;
    }
    .nav-custom.affix a:link, .nav-custom.affix a:visited, .nav-custom.affix a:hover, .nav-custom.affix a:active {
        text-decoration: none;
        color:  #f87f73;
        outline: none;
    }
}
@media (max-width: 767px) {
    .navbar-collapse {
        width: 250px;
        position: fixed;
        right: -250px;
        top: 80px;
        overflow-x: hidden;
        background-color: rgba(255, 255, 255, 0.8);
        border-top: none;
        -webkit-box-shadow: none;
        box-shadow: none;
        -webkit-transition: all .35s ease;
        -o-transition: all .35s ease;
        transition: all .35s ease;
    }
    .navbar-collapse.in {
        right: 0px;
        width: 250px;
        -webkit-transition: all .35s ease;
        -o-transition: all .35s ease;
        transition: all .35s ease;
    }
    .navbar-collapse.collapsing {
        height: auto !important;
    }
    .navbar-nav {
        margin: 0 -15px;
    }
    .navbar-nav>li>a {
        padding: 0;
        line-height: 3em;
        text-align: center;
    }
    .navbar-collapse ul {
        border-left: 1px solid rgba(0, 0, 0, .18);
    }
    .navbar-collapse ul li {
        border-bottom: 1px solid rgba(0, 0, 0, .18);
    }
    .navbar-collapse ul li:hover {
        background-color: #f87f73;
        color: #fff;
        -webkit-transition: all .35s ease;
        -o-transition: all .35s ease;
        transition: all .35s ease;
    }
    .navbar-collapse ul a:link,
    .navbar-collapse ul a:visited {
        color: #f87f73;
    }
    .navbar ul a:hover {
        text-decoration: none;
        color: #fff;
    }
}

      

How it works:

  • The navbar-fixed-top class is used in place of custom styles.
  • Instead of writing your own javascript to handle your nav on scrolling, you can use Bootstrap Affix . This built-in javascript plugin can use the data-offset-top attribute to set the point at which the affix class is automatically added to the element where the spy-spy attribute is set. By using data attributes you don't need a single line of javascript, just add styles for how you want your element to look when the class is applied . Now all of your styles are in your CSS, and none of them should be in your javascript. affix

  • Use the built-in navbar-toggle which uses the built-in Bootstrap Collapse plugin to navigate to and from mobile navigation. This eliminates the need to write / test / maintain native javascript and eliminates duplicate markup for the menu. The collapse plugin applies the class to the element with the collapse class when expanding the menu, so you can simply use it to style your menu. in

  • Use media queries to change the menu layout based on the size of the viewport. The "mobile" menu only appears on viewports smaller than 767 pixels, so you can easily target how you want your mobile menu to appear.

Overall, the CSS is almost identical to CSS, I just changed the selector to reflect the changes in the markup. Apart from a few minor tweaks, it was heavily cut and pasted from your site.

+2


source


When the page opens, your nav is insisde block HTML

<div class="row nav-custom nav-custom"> ... </div>

      

And when scrolling, the navigator is inside the block

<div class="row nav-custom nav-custom-2"> ... </div>

      

In your stylesheet http://rohanchhabra.in/css/custom.css you have an addition: 25px; and addition: 14px; for .nav-custom and .nav-custom-2 , which splits the Bootstrap grid because there isn't enough room to fit your col-sm-3 and col-sm-9 without breaking the line into two lines.

You can remove or edit the padding for these 2 classes to avoid adding extra horizontal space, for example.



.nav-custom{
padding-top:15px;
padding-bottom:15px;
}

      

or put the nav-custom class inside your col class eg.

<div class="row">
  <div class="col-xs-3 col-sm-3">  
    <div class="nav-custom">  ... </div>
  </div>
  ...
</div>    

      

The key point here is that you never want to have horizontal padding on any bootstrap row or column element, or you risk breaking the Bootstrap grid

Good luck!

+1


source


You can try using media queries for different window sizes.

https://developers.google.com/web/fundamentals/layouts/rwd-fundamentals/use-media-queries?hl=en .

This might be helpful for you.

+1


source


You might be facing a Safari web browser error as this problem seems to be recreated only on Mac computers. I can recreate the problem on OSX 10.8 by running Safari 6.1. Refreshing the browser or clicking on any of the navigation values ​​fixes the problem and resets the navigation display to the desired position. You can find a bug for this potential Safari display issue.

As I said, my suggestion to solve this is to refactor your HTML to better use Bootstrap's core navigation components. Currently you have split navigation in different divs and it is split for wide screen and mobile. A more standard Bootstrap navigation element would look like this:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Static navbar -->
            <nav class="navbar navbar-custom navbar-inverse navbar-fixed-top" role="navigation">
                  <div class="container" id="nav-container">
                    <!-- Brand and toggle get grouped for better mobile display -->
                    <div class="navbar-header">
                          <a class="navbar-brand" href=""><img src="" class="Logo" alt="Rohan Chhabra Designer and Developer"></a>
                      <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>
                
                    <!-- 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="#home">Home</a></li>
                         <li><a href="#design">Design</a></li>
                         <li><a href="#develop">Develop</a></li>
                         <li><a href="#contact">Contact</a></li>   
                      </ul>
                      
                    </div><!-- /.navbar-collapse -->
                  </div><!-- /.container-fluid -->
                </nav>
        <!-- End Static navbar -->
      

Run codeHide result


Surely you need to add some custom.css styling to this code example and it assumes your logo is an image (so redesign it accordingly) BUT I think that by using this more standard navigation when implementing Bootstrap navigation you will in better shape in the long run. I have tested Boostrap websites using this style navigation and they have no problem displaying Safari in your example.

0


source


I am validating your site with w3c validator .

Some critical problems must be correct.

<meta http-equiv="X-UA-Compatible" content="IE=edge">

      

I recommend that this line comes with IE conditional comments as shown below.

<!-- [if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"> -->

      

And Anchor tag is not allowed as child of ul

Please report these issues and check. This will definitely fix your site's problems.

0


source







All Articles