-3

I don't know why Bootstrap is doing this. I want the whole background of the website to be black and for that I'm doing this inside HTML file

<body>
    <div id="fullWrapper">
        <section id="welcomeSection">
            <div class="container">
                <p style="margin-top:30px;">Welcome to the website. This website was made to test the light and dark modes with bootstrap</p>
            </div>
        </section>
    </div>
</body>

and inside css file.

#fullWrapper {
    background: rgb(0, 0, 0);
    height: 1000px;
}

but the output is leaving a white space of 30px from the top. See this output

1 Answers1

-1

That space is from the paragraph margin-top: 30px; which is caused from margin collapsing. If there is no border, padding, etc. on the parent element to separate margin-top on the first child block, then those margins collapse.

Here is further explanation about margin collapsing on MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Mastering_margin_collapsing

There are multiple ways to get rid of that white space. Remove the margin from the paragraph and replace it with padding-top: 30px; or add at least padding-top: 1px; to either the .container or #welcomeSection divs.

pavger
  • 684
  • 2
  • 11
  • 21
  • this is not enough as an explanation. Margin is meant to add space oustide the element and inside it's parent container, so you need to say that we have margin-collpasing issue which make this margin go outside and thus creating this issue – Temani Afif Jan 31 '18 at 18:58
  • Ok I'll update my answer. Thank you for the suggestion. – pavger Jan 31 '18 at 19:05