1

I have a gap between a "container" div and top of the page. If I give the contained a -20px margin it removes the gap, but I am looking for a solution that does not need to manipulate the css file that way. The gap looks to be a part of body. I have given 0 padding and 0 margin to the body of page, but the gap is still there. Where is the problem?

container backgroud=red

body background=green

enter image description here

html base file

{% load staticfiles %}

<!DOCTYPE html>
<html lang="en" class="no-js">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
        <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
        <title>Google</title>
        <meta name="description" content="Blueprint: Horizontal Drop-Down Menu" />
        <meta name="keywords" content="horizontal menu, microsoft menu, drop-down menu, mega menu, javascript, jquery, simple menu" />
        <meta name="author" content="Codrops" />
        <link rel="shortcut icon" type="image/png" href="{{STATIC_URL}}/favicon.ico"/>      
        <link type="text/javascript" href="{% static 'MMR/js/topnavbar.js' %}">

        <!-- top nav scripts-->

    </head>

    <body>
        {% include 'MMR/topnavbar.html' %}

        {% block content %}
        {% endblock %}

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <script src="static/MMR/js/cbpHorizontalMenu.min.js"></script>
        <script>
            $(function() {
                cbpHorizontalMenu.init();
            });
        </script>
    </body>
</html>

html extension:

        <head>
            <link rel="stylesheet" type="text/css" href="{% static 'MMR/css/topnav-default.css' %}">
            <link rel="stylesheet" type="text/css" href="{% static 'MMR/css/topnav-component.css' %}">
        </head>

        <div class="container">
            <header class="clearfix">
                <!--<span>Tagline</span>-->
                <h1>Application</h1>
                <nav>
                    <a href="http://tympanus.net/Blueprints/FullWidthImageSlider/" class="icon-arrow-left" data-info="previous Step">Previous Blueprint</a>
                    <a href="http://tympanus.net/codrops/?p=14426" class="icon-drop" data-info="Next Step">back to the Codrops article</a>
                </nav>
            </header>   

            <div class="main">
                <nav id="cbp-hrmenu" class="cbp-hrmenu">
                    <ul>
                        <li>
                            <a href="#">Products</a>
                            <div class="cbp-hrsub">
                                <div class="cbp-hrsub-inner"> 
                                    <div>
                                        <h4>Learning &amp; Games</h4>
                                        <ul>
                                            <li><a href="#">Catch the Bullet</a></li>
                                            <li><a href="#">Snoopydoo</a></li>
                                            <li><a href="#">Fallen Angel</a></li>
                                            <li><a href="#">Sui Maker</a></li>
                                            <li><a href="#">Wave Master</a></li>
                                            <li><a href="#">Golf Pro</a></li>
                                        </ul>
                                    </div>
                                    <div>
                                        <h4>Utilities</h4>
                                        <ul>
                                            <li><a href="#">Gadget Finder</a></li>
                                            <li><a href="#">Green Tree Express</a></li>
                                            <li><a href="#">Green Tree Pro</a></li>
                                            <li><a href="#">Wobbler 3.0</a></li>
                                            <li><a href="#">Coolkid</a></li>
                                        </ul>
                                    </div>
                                    <div>
                                        <h4>Education</h4>
                                        <ul>
                                            <li><a href="#">Learn Thai</a></li>
                                            <li><a href="#">Math Genius</a></li>
                                            <li><a href="#">Chemokid</a></li>
                                        </ul>
                                        <h4>Professionals</h4>
                                        <ul>
                                            <li><a href="#">Success 1.0</a></li>
                                            <li><a href="#">Moneymaker</a></li>
                                        </ul>
                                    </div>
                                </div><!-- /cbp-hrsub-inner -->
                            </div><!-- /cbp-hrsub -->
                        </li>
                        <li>
                            <a href="#">Downloads</a>
                            <div class="cbp-hrsub">
                                <div class="cbp-hrsub-inner">
                                    <div>
                                        <h4>Education &amp; Learning</h4>
                                        <ul>
                                            <li><a href="#">Learn Thai</a></li>
                                            <li><a href="#">Math Genius</a></li>
                                            <li><a href="#">Chemokid</a></li>
                                        </ul>
                                        <h4>Professionals</h4>
                                        <ul>
                                            <li><a href="#">Success 1.0</a></li>
                                            <li><a href="#">Moneymaker</a></li>
                                        </ul>
                                    </div>
                                    <div>
                                        <h4>Entertainment</h4>
                                        <ul>
                                            <li><a href="#">Gadget Finder</a></li>
                                            <li><a href="#">Green Tree Express</a></li>
                                            <li><a href="#">Green Tree Pro</a></li>
                                            <li><a href="#">Holy Cannoli</a></li>
                                            <li><a href="#">Wobbler 3.0</a></li>
                                            <li><a href="#">Coolkid</a></li>
                                        </ul>
                                    </div>
                                    <div>
                                        <h4>Games</h4>
                                        <ul>
                                            <li><a href="#">Catch the Bullet</a></li>
                                            <li><a href="#">Snoopydoo</a></li>
                                            <li><a href="#">Fallen Angel</a></li>
                                            <li><a href="#">Sui Maker</a></li>
                                            <li><a href="#">Wave Master</a></li>
                                            <li><a href="#">Golf Pro</a></li>
                                        </ul>
                                    </div>
                                </div><!-- /cbp-hrsub-inner -->
                            </div><!-- /cbp-hrsub -->
                        </li>
                        <li>
                            <a href="#">Applications</a>
                            <div class="cbp-hrsub">
                                <div class="cbp-hrsub-inner"> 
                                    <div>
                                        <h4>Learning &amp; Games</h4>
                                        <ul>
                                            <li><a href="#">Catch the Bullet</a></li>
                                            <li><a href="#">Snoopydoo</a></li>
                                        </ul>
                                        <h4>Utilities</h4>
                                        <ul>
                                            <li><a href="#">Gadget Finder</a></li>
                                            <li><a href="#">Green Tree Express</a></li>
                                            <li><a href="#">Green Tree Pro</a></li>
                                            <li><a href="#">Wobbler 3.0</a></li>
                                            <li><a href="#">Coolkid</a></li>
                                        </ul>
                                    </div>
                                    <div>
                                        <h4>Education</h4>
                                        <ul>
                                            <li><a href="#">Learn Thai</a></li>
                                            <li><a href="#">Math Genius</a></li>
                                            <li><a href="#">Chemokid</a></li>
                                        </ul>
                                        <h4>Professionals</h4>
                                        <ul>
                                            <li><a href="#">Success 1.0</a></li>
                                            <li><a href="#">Moneymaker</a></li>
                                        </ul>
                                    </div>
                                </div><!-- /cbp-hrsub-inner -->
                            </div><!-- /cbp-hrsub -->
                        </li>
                        <li>
                            <a href="#">Projects</a>
                            <div class="cbp-hrsub">
                                <div class="cbp-hrsub-inner"> 
                                    <div>
                                        <h4>Learning &amp; Games</h4>
                                        <ul>
                                            <li><a href="#">Catch the Bullet</a></li>
                                            <li><a href="#">Snoopydoo</a></li>
                                            <li><a href="#">Fallen Angel</a></li>
                                            <li><a href="#">Sui Maker</a></li>
                                            <li><a href="#">Wave Master</a></li>
                                            <li><a href="#">Golf Pro</a></li>
                                        </ul>

                                    </div>
                                    <div>
                                        <h4>Entertainment</h4>
                                        <ul>
                                            <li><a href="#">Gadget Finder</a></li>
                                            <li><a href="#">Green Tree Express</a></li>
                                            <li><a href="#">Green Tree Pro</a></li>
                                            <li><a href="#">Holy Cannoli</a></li>
                                            <li><a href="#">Wobbler 3.0</a></li>
                                            <li><a href="#">Coolkid</a></li>
                                        </ul>
                                    </div>
                                </div><!-- /cbp-hrsub-inner -->
                            </div><!-- /cbp-hrsub -->
                        </li>

                    </ul>
                </nav>
            </div>

        </div>

css 1:

/* General Demo Style */

@import url(http://fonts.googleapis.com/css?family=Lato:300,400,700);

@font-face {
    font-family: 'fontawesome';
    src:url('../fonts/fontawesome.eot');
    src:url('../fonts/fontawesome.eot?#iefix') format('embedded-opentype'),
        url('../fonts/fontawesome.svg#fontawesome') format('svg'),
        url('../fonts/fontawesome.woff') format('woff'),
        url('../fonts/fontawesome.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

body, html { font-size: 100%; padding: 0; margin: 0;}

/* Reset */
*,
*:after,
*:before {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

/* Clearfix hack by Nicolas Gallagher: http://nicolasgallagher.com/micro-clearfix-hack/ */
.clearfix:before,
.clearfix:after {
    content: " ";
    display: table;
}

.clearfix:after {
    clear: both;
}


body {
    font-family: 'Lato', Calibri, Arial, sans-serif;
    color: #47a3da;
}

a {
    color: #f0f0f0;
    text-decoration: none;
}

a:hover {
    color: #000;
}

.container{
    background-color:red;
    padding-top:0px;
}
.container > header {
    width: 90%;
    max-width: 70em;
    margin: 0 auto; /* remove auto to push the h1 text to left*/
    padding: 0 0.5em 0.5em 0.5em;   
    background-color:yellow;

}

/* Brand Name Text */
.container > header h1 {
    font-size: 1.5em;
    line-height: 1.3;
    margin: 0;
    float: left;
    font-weight: 400;
    margin-top:0;
}

.container > header span {
    display: block;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5em;
    padding: 0 0 0.1em 0.1em;
}

.container > header nav {
    float: right;
}
/* next previous icons*/
.container > header nav a {
    display: block;
    float: left;
    position: relative;
    width: 2.5em;
    height: 2.5em;
    background: #fff;
    border-radius: 50%;
    color: transparent;
    margin: 0 0.5em;
    border: 4px solid #47a3da;
    text-indent: -8000px;
}

/* after click next previous icons*/
.container > header nav a:after {
    content: attr(data-info);
    color: #47a3da;
    position: absolute;
    width: 600%;
    top: 120%;
    text-align: right;
    right: 0;
    opacity: 0;
    pointer-events: none;
}

.container > header nav a:hover:after {
    opacity: 1;
}
/* hover next previous icons*/
.container > header nav a:hover {
    background: #47a3da;
}

.icon-drop:before, 
.icon-arrow-left:before {
    font-family: 'fontawesome';
    position: absolute;
    top: 0;
    width: 100%;
    height: 100%;
    speak: none;
    font-style: normal;
    font-weight: normal;
    line-height: 2;
    text-align: center;
    color: #47a3da;
    -webkit-font-smoothing: antialiased;
    text-indent: 8000px;
    padding-left: 8px;
}

.container > header nav a:hover:before {
    color: #fff;
}

.icon-drop:before {
    content: "\e000";
}

.icon-arrow-left:before {
    content: "\f060";
}

css 2:

/* menu separator */
.cbp-hrmenu {
    width: 100%;
    margin-top: 0em;
    border-bottom: 4px solid #47a3da;
}

/* general ul (div of tabs) */
.cbp-hrmenu ul {
    margin: 0;
    padding: 0;
    list-style-type: none;

}

/* first level ul style (div of tabs)*/
.cbp-hrmenu > ul,
.cbp-hrmenu .cbp-hrsub-inner {
    width: 90%;
    max-width: 70em;
    margin: 0 auto; /*remove auto to push tabs to left*/
    padding: 0 1.875em;

}
/* tabs individually + the menu that drops*/
.cbp-hrmenu > ul > li {
    display: inline-block;
}

/* link (text) of tabs */
.cbp-hrmenu > ul > li > a {
    font-size:1.1em;
    font-weight: 700;
    padding: 0.1em 1em; /* height of tabs*/
    color: #999;
    display: inline-block;
    border-radius:0.5em 0.5em 0em 0em;

}
/* hover tabs' text */
.cbp-hrmenu > ul > li > a:hover {
    color: #47a3da;
    transition: color 0.2s linear;

}

/* links inside the drop down menu */
.cbp-hrmenu > ul > li.cbp-hropen a,
.cbp-hrmenu > ul > li.cbp-hropen > a:hover {
    color: #fff;
    background: #47a3da;
}

/* sub-menu (the one that drops and contains options)*/
.cbp-hrmenu .cbp-hrsub {
    display: none;
    position: absolute;
    background: #47a3da;
    width: 100%;
    left: 0;
}

.cbp-hropen .cbp-hrsub {
    display: block;
    padding-bottom: 3em;
}

.cbp-hrmenu .cbp-hrsub-inner > div {
    width: 33%;
    float: left;
    padding: 0 2em 0;
}

.cbp-hrmenu .cbp-hrsub-inner:before,
.cbp-hrmenu .cbp-hrsub-inner:after {
    content: " ";
    display: table;
}

.cbp-hrmenu .cbp-hrsub-inner:after {
    clear: both;
}

.cbp-hrmenu .cbp-hrsub-inner > div a {
    line-height: 2em;
}

.cbp-hrsub h4 {
    color: #afdefa;
    padding: 2em 0 0.6em;
    margin: 0;
    font-size: 160%;
    font-weight: 300;
}

/* Examples for media queries */

@media screen and (max-width: 52.75em) { 

    .cbp-hrmenu {
        font-size: 80%;
    }

}

@media screen and (max-width: 43em) { 

    .cbp-hrmenu {
        font-size: 120%;
        border: none;
    }

    .cbp-hrmenu > ul,
    .cbp-hrmenu .cbp-hrsub-inner {
        width: 100%;
        padding: 0;
    }

    .cbp-hrmenu .cbp-hrsub-inner {
        padding: 0 2em;
        font-size: 75%;
    }

    .cbp-hrmenu > ul > li {
        display: block;
        border-bottom: 4px solid #47a3da;
    }

    .cbp-hrmenu > ul > li > a { 
        display: block;
        padding: 1em 3em;
    }

    .cbp-hrmenu .cbp-hrsub { 
        position: relative;
    }

    .cbp-hrsub h4 {
        padding-top: 0.6em;
    }

}

@media screen and (max-width: 36em) { 
    .cbp-hrmenu .cbp-hrsub-inner > div {
        width: 100%;
        float: none;
        padding: 0 2em;
    }
}

Inspection on Chrome shows a section that I have no idea what it is. When I remove it, the gap goes away. Here is the snapshot:

enter image description here

Ibo
  • 4,081
  • 6
  • 45
  • 65
  • Headers often have a default top margin (and it can collapse with the parent margin). Try `margin-top: 0` on the `h1`. – Michael Benjamin Jan 03 '17 at 23:59
  • You need to provide the CSS that contains `container`, `clearfix` and `main`, the one you provided is irrelevant. – Paul Abbott Jan 04 '17 at 00:00
  • If you want to get rid of all untoward margins and paddings, you can do `* { margin: 0; padding: 0; }` at the top of the CSS-file. However, this has some unwanted results (possibly), in that it removes all paddings and margins, and you have to add quite a bit of that yourself to elements you use. A smarter way might be to reuse a proper `reset.css`. There are plenty of them around if you Google. – junkfoodjunkie Jan 04 '17 at 00:06
  • I added the second css file – Ibo Jan 04 '17 at 00:10
  • @junkfoodjunkie It worths a full answer. – kind user Jan 04 '17 at 00:12
  • @junkfoodjunkie I added `* { margin: 0; padding: 0; } ` to the top of the css file and guess what? the gap is still there – Ibo Jan 04 '17 at 00:51
  • I dumped all of your code into a fiddle and there's no issue. https://jsfiddle.net/dqm00eLx/ – Serg Chernata Jan 04 '17 at 01:16
  • @Serg Chernata It is strange. That tells us the problem is the browser=Chrome? – Ibo Jan 04 '17 at 01:20
  • @Ibo possibly, browsers may have style customizations. Also, clearing your cache. Hold shift when you click refresh, etc. – Serg Chernata Jan 04 '17 at 01:21
  • @Serg Chernata it is the same on IE. I load using CTRL+F5 to make sure I load all of the static files and clear the cache. – Ibo Jan 04 '17 at 01:22
  • @Ibo interesting, can you try hosting this online somewhere? Maybe create your own fiddle? It's tough to help otherwise. – Serg Chernata Jan 04 '17 at 01:24
  • @SergChernata I have not deployed it yet, how can I give access to you? fiddlejs is not showing it as you tried – Ibo Jan 04 '17 at 01:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/132245/discussion-between-serg-chernata-and-ibo). – Serg Chernata Jan 04 '17 at 01:29
  • You are not giving us all the details. Copying and pasting your code above into a jsfiddle yields the results you want: https://jsfiddle.net/dsq6ubs6/ – Ryan Wheale Jan 04 '17 at 01:43
  • @RyanWheale how can I give more details? I am developing a django app, I only have 2 html files, one is the base file and the other is the extension file. I use 2 css files to style and you have them. I use djangi 1.10 and Google Chrome to test. – Ibo Jan 04 '17 at 01:47
  • Let me ask this - how do you expect us to help you when the code you posted works? You're going to have to figure this out on your own (unless you can get your app running on a server and give us a link). Either way this is going to involve the crappiest type of debugging: remove one element at a time until the problem goes away and investigate from there. You can do this using the browser inspector. – Ryan Wheale Jan 04 '17 at 01:57
  • @RyanWheale believe me I have remove all of the elements and the gap is not going anywhere. I will deploy this in the near future and will comment here so that people can have a look on their own browser so we can figure this out. Thanks! – Ibo Jan 04 '17 at 02:01
  • If you just right-click and chose "view source" - do you see anything above the ` `-declaration? – junkfoodjunkie Jan 04 '17 at 02:09
  • I edited the question with more information. I added the base html file too. That is all I have. – Ibo Jan 04 '17 at 02:25
  • I managed to deploy this so you can have more freedom to dig more: http://ejeddi.pythonanywhere.com/ – Ibo Jan 05 '17 at 20:54

4 Answers4

2

you have to add the style to the body tag like following

body{margin-top : 0px;}

This will override the browser default properties. You can see the browser default css So you can override any of these default properties to achieve custom design.

Md Johirul Islam
  • 5,042
  • 4
  • 23
  • 56
  • It did not help. Others mentioned it too before, but it seems it is not the issue. – Ibo Jan 04 '17 at 01:44
  • Probably now i got what you want. You want to remove the padding from top of navigation bar? Am i right? – Md Johirul Islam Jan 04 '17 at 02:13
  • You are probably trying to do something other as I understood from statement. If you want to remove the space from top of nav bar then you have to remove margin top from the div that is creating the nav bar. Can you create a [jsfiddle](https://jsfiddle.net/) – Md Johirul Islam Jan 04 '17 at 02:17
  • Please read the other comments and the question again (I added stuff). The problem is not the padding or margin it seems – Ibo Jan 04 '17 at 02:21
1

After troubleshooting and looking for hidden or erroneous UTF characters we figured out that the cause was an un-closed meta charset tag.

<meta charset="UTF-8"/>
Community
  • 1
  • 1
Serg Chernata
  • 12,280
  • 6
  • 32
  • 50
  • This was caused by copy pasting the code from a website. In such cases the best practice is to use a browser inspection (right click on Chrome and select Inspect), then if there is any unexpected translation of html code can be visualized. Since in such cases the character is invisible, I used Notepad++, Tab View/See All Symbols to find where the problematic unwanted is. – Ibo Jan 06 '17 at 03:22
0

Your title in <h1> overflows the div containing it, if you have an inspector on your brower use it and look at <h1>.

Solutions could be to set <h1> margin top to 0px.

h1 {
  margin-top: 0px;
}

Set <header> overflow to hidden should work too.

gdforj
  • 153
  • 2
  • 10
0

Some browsers override their default stylesheet.

For example chrome browser override following css.

body { margin:8px }

So, you have to do like this.

body { margin:0px; }
Smith Lee
  • 340
  • 2
  • 9
  • I just noticed that I had the css file copied twice on the question. I just corrected it and as you can see the line `body, html { font-size: 100%; padding: 0; margin: 0;}` ensure that, but the gap is still there. I am using chrome. – Ibo Jan 04 '17 at 01:12
  • You don't have a body tag in your html. Wrap your "container" div with body tag. It works in chrome. – Smith Lee Jan 04 '17 at 01:35
  • @ SmithLee I have a body tag in the base html file. If you are familiar with django, you can extend your templates. In my case the html code that I have shared is positioned between body tags in the base html file, so that cannot be the issue – Ibo Jan 04 '17 at 01:41