0

Whenever a div is nested inside another div and the nested div is given margin through CSS, the margin is supposed to be set according to the parent/container div.

But I have tried and what actually happens is that the child div's margin is set according to 'last element' rather than the previous div.

    <!DOCTYPE html>
<html lang="en">
    <head>
        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

        <title>Web Dev Checklist - Henry Spike</title>

        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
        <link href="https://fonts.googleapis.com/css?family=Ranga" rel="stylesheet">
        <style type="text/css">
            #main {
                background-color: #93628F;
                min-height: 100vh;
                height: 100%;
                color: white;
                font-family: 'Ranga', cursive;
            }
            #main-heading {
                margin-top: 100px;
            }
        </style>
    </head>
    <body>
        <div id="main">
            <div class="container">
                <div class="row" id="main-heading">
                    <div class="col-sm-12 text-center">
                        <h1>Web Developer Checklist - Henry Spike</h1>
                    </div>
                </div>
            </div>
        </div>

        <!-- jQuery first, then Tether, then Bootstrap JS. -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
    </body>
</html>

And the output can be seen on http://www.henryspike.tk/checklist You can see the white space above the background color which implies that margin is being set according to the browser top/previous element.

I even tried this on divs without the bootstrap classes to check to see if this was a Bootstrap Issue. But it outputs the same result

Carol Skelly
  • 351,302
  • 90
  • 710
  • 624
Parker Queen
  • 619
  • 2
  • 12
  • 27

0 Answers0