Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css HTML5中的布局问题_Css_Html - Fatal编程技术网

Css HTML5中的布局问题

Css HTML5中的布局问题,css,html,Css,Html,我想从顶部对齐div请帮助我解决此问题 我的代码是: <!DOCTYPE html> <html> <head> <style> body { margin:0; padding:0; } .topmenu { background-color:#808080; height:200px;

我想从顶部对齐div请帮助我解决此问题
我的代码是:

<!DOCTYPE html>
<html>
<head>
<style>
        body {
            margin:0;
            padding:0;
        }
        .topmenu {
            background-color:#808080;
            height:200px;
            width:600px;
        }
    </style>
</head>
<body>
<nav>
    <div class="topmenu">
    <h2>Hello</h2>
    </div>
</nav>
</body>
</html>

身体{
保证金:0;
填充:0;
}
.topmenu{
背景色:#808080;
高度:200px;
宽度:600px;
}
你好

正文{
保证金:0;
填充:0;
}
.topmenu{
背景色:#808080;
高度:200px;
宽度:600px;
}
氢{
保证金:0;
}

你好

您也可以在不添加其他类的情况下尝试此操作

body 
{
    margin:0;
    padding:0;
}
.topmenu 
{
    background-color:#808080;
    height:200px;
    width:600px;
    margin-top: -19px;
}
正文{
保证金:0;
填充:0;
}
.topmenu{
背景色:#808080;
高度:200px;
宽度:600px;
}
氢{
保证金:0;
}

你好

以上答案绝对正确。只是想补充一点,使用或处理网页的默认样式是一种很好的做法。使用它们可以避免许多与样式相关的障碍。
就答案而言

h2{margin:0;padding:0}
应该可以很好地工作

是否要在布局中将div作为标题对齐?请阅读“”
body 
{
    margin:0;
    padding:0;
}
.topmenu 
{
    background-color:#808080;
    height:200px;
    width:600px;
    margin-top: -19px;
}
.topmenu 
  {
    float:left;
    padding:5px;
  }