为什么是宽度100%的html代码全栏不工作,当我写.忘了那个吧,连复制粘贴都不起作用.为什么

Why is the html code of width 100% for full bar is not working when I am writing. Forget about that, even the copy paste is not working. Why?

本文关键字:为什么 忘了 复制 不起作用 html 100% 代码 工作      更新时间:2023-09-26

我的基本代码也不工作,这是我为div试图扩展到全窗口。

<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div style="width:100%; position:relative; height:100px; background-color:#F00;"></div>
</body>
</html>

这就是我试图通过复制粘贴来做的,即使我复制粘贴也失败了。

这是原始代码,如下图所示

http://codepen.io/chriscoyier/pen/PwzBBw

这是复制粘贴代码,我在下面做了

http://codepen.io/anon/pen/GJVMeE

这是由浏览器默认的CSS造成的。它们通常有一些padding, margin和其他默认值。

使用normalize.css或reset.css图层来清除所有默认值,然后自己重新设置。

CSS图层:https://github.com/necolas/normalize.css/或http://yuilibrary.com/yui/docs/cssnormalize/

在您的示例中,在normalize库中复制的原始内容之间存在差异。(设置-> CSS -> Normalize)

删除溢出-x: hidden;规则从html,正文选择器和你的标题栏将扩展全宽度

http://codepen.io/anon/pen/VLorxr

html,body {
/*overflow-x: hidden;*/

}