html - Div 离开屏幕
问题描述
我不知道如何解释它,但这里是代码:
CSS:
.top-container
{
background-color: #2f2f2f;
float: left;
width: 1920px;
}
HTML:
<html>
<head>
<link rel="stylesheet" href="style/main.css">
<link href="https://fonts.googleapis.com/css?family=Comfortaa">
</head>
<body>
<div class="top-container">
<h1>
Text
</h1>
<h4>
some more text :)</b>
</h4>
</div>
</body>
</html>
结果并不像预期的那样:
解决方案
body
边距默认为 8px,您需要将其设置为 0。
此外,将top-container
宽度更新为 100%。
body {
margin: 0;
}
.top-container {
background-color: #2f2f2f;
float: left;
width: 100%; // fix this from 1920px to 100%
}
<html>
<head>
<link rel="stylesheet" href="style/main.css">
<link href="https://fonts.googleapis.com/css?family=Comfortaa">
</head>
<body>
<div class="top-container">
<h1>
Text
</h1>
<h4>
some more text :)</b>
</h4>
</div>
</body>
</html>
推荐阅读
- angular - 如果某个网站已使用 Karma - Jasmine 打开,我如何进行单元测试?
- javascript - 不和谐音乐机器人随机切断音乐
- java - 带有 Mockito 的 JerseyTest 框架 - 连接被拒绝:连接
- python - Python 黯淡和 tkinter
- azure-devops - 在 Azure DevOps 中自定义合并提交消息并没有真正起作用
- zsh - zsh:行以空字符开头,后跟用户名。如何删除这个额外的空间?
- .htaccess - 如何删除尾部斜杠?我当前的 htaccess 代码不起作用
- matlab - 从图像法线坐标进行圆柱投影
- laravel - 不支持的驱动程序 [https],部署到 heroku 时的 laravel
- html - 我无法将导航栏项目移动到右侧而不是左侧