I am working on HTML and having an issue with what I think is margin collapse. When I take out the line "border:solid black 1px;" from the Div #body in my css, it causes the Div #header to drop about 20% on the page. I can't figure out WHY it is doing that, or how to fix it. I have tried making the body Div border 0px and it does the same thing. If I take the body Div out entirely, it does the same thing.

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Cast & Crew - Home Page</title>
<style type="text/css"> 

</style>
<link href="css2.css" type="text/css"                        
              rel="stylesheet" />

</head>

<body>
<div id="body">
<div id ="header">
    <span class="float"><img class="img" src = "face2.png" alt="Face mask"></span>
        Cast & Crew Restaurant

    <span class="floatr"><img class="img" src = "face.png" alt="Face mask"></span>


<table id="links">
<tr>
    <th><a href="Home.html"> Home</a></th>
    <th><a href="Menu.html"> Menu</a></th>
    <th><a href="plabout.html">About Us</a></th>
    <th><a href="Contact.html">Contact</a></th>
</tr>
</table>
</div>
<div class ="sidebar">
<table>
    <tr><td><a href="#app">Appetizers</a></td></tr>
    <tr><td><a href="#salad">Salads</a></td></tr>
    <tr><td><a href="#burger">Burgers</a></td></tr>
    <tr><td><a href="#sand">Sandwiches</a></td></tr>
    <tr><td><a href="#pasta">Pasta</a></td></tr>
    <tr><td><a href="#entree">Entrées</a></td></tr>
    <tr><td><a href="#pizza">Pizza</a></td></tr>

</table>
</div>
</div>
</body>
</html>

And here is the CSS code

a:link {color:#FFFFFF;}
a:visited {color:#0066FF}
a:hover {color:#3385FF;}
a:focus {color:#B20000;}
a:active {background-color: white; color:black;}

.blankrow{height: 40px !important; 
    }

#body   {height: 1150px; width: 100%;
    border:solid black 2px;}


#header     {position: fixed;
    background:black;
    height: 160px;width: 100%;
    text-align: center;
        font-size:40pt;
        text-shadow:5px 4px 10px #FF0000,-5px -4px 10px #FFFFFF;
        color:#000000;

        }

html        {background-image: url("bg.jpg");
        background-repeat:no-repeat;
        background-position; 50%, 50%;
        background-attachment: fixed;
        min-height:100%;
        background-size:cover;
        color:#FFFFFF;
        }

.img    {width: 50px; height:85px;}

#links  {width:50%; 
    height:50px;
    font-size:22pt;     
    margin:auto;
    text-shadow:0px 0px 0px #000000;
    }

#menu   {height: 3200px;
    width: 900px;

    margin-top:15%;
    margin-left:17%;
    font-size:18pt;}

.sidebar {width: 150px;
    height: 230px;
    position: fixed;
    left: 40px;
    top: 300px;
    font-size:18pt;
    border:solid black 2px;}

.spacer{height: 10px !important; }
有帮助吗?

解决方案

Applying top:0 for #header will fix the issue

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top