边距崩溃导致 Div 移动



我正在研究 HTML,但我认为是边距崩溃的问题。当我从 css 中的 Div #body 中取出"border:solid black 1px;"行时,它会导致 Div #header 在页面上下降约 20%。我不知道它为什么要这样做,或者如何解决它。我尝试使正文 Div 边框为 0px,它做同样的事情。如果我完全取出身体 Div,它会做同样的事情。

<!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>

这是CSS代码

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; }

应用 top:0对于 #header 将解决问题

最新更新