Html DIV元素没有';不适合网页长度
我使用这个div元素作为添加到body元素的图像的第二个背景,但是它从来没有正常工作过,因为底部的边在长度上永远不匹配。 这是一本书 我确实让它工作过一次,但当我修改任何其他元素时,它总是变得一团糟。 我也有同样的宽度问题。 我希望你能帮上忙,因为这件事困扰着我 我的CSS:Html DIV元素没有';不适合网页长度,html,css,Html,Css,我使用这个div元素作为添加到body元素的图像的第二个背景,但是它从来没有正常工作过,因为底部的边在长度上永远不匹配。 这是一本书 我确实让它工作过一次,但当我修改任何其他元素时,它总是变得一团糟。 我也有同样的宽度问题。 我希望你能帮上忙,因为这件事困扰着我 我的CSS: html, body { height: 100 % ; width: 100 % ; margin: 0; padding: 0; } body { background: url
html, body {
height: 100 % ;
width: 100 % ;
margin: 0;
padding: 0;
}
body {
background: url('../images/choc1.jpg');
font - family: arial,
Myriad pro,
sans serif;
color: #1E1B1B;
background-repeat: no-repeat;
background-attachment: fixed;
padding:0;
margin:0;
}
# page {
width: 1233.5 px;
background - color: rgba(255, 255, 255, 0.7);
position: absolute;
margin - left: 60 px;
margin - right: 0 px;
margin - bottom: 0 px;
padding: 0 px;
min - height: 100 % ;
}
我的HTML:
<body>
<div id="page">
</div>
所以我写了一个例子,应该对您有所帮助 因此,您将page div设置为绝对位置元素,这使得它很难放置在其他对象中。“绝对”是一种定位,它忽略了其他所有东西的位置,而只是将它们放置在某个位置。您应该很少/永远不要在这样的容器中使用它 我添加的真正重要的一行是
margin:0auto
将其放置在父容器的中心(水平)。(它所在的容器)我还在主体上添加了填充,将页面容器推入,而不是使用边距
您还可以在几个小时内查看此代码笔:
为了获得良好的实践,请给您的html div一个类
<body>
<div id="page" class="PageClass">
</div>
使用vh和vw将使div动态化,并与所有设备尺寸兼容。毫不费力地
祝我的朋友好运欢迎来到Stack Overflow!请看一下,仔细阅读,尤其是和.thnx以获得帮助,兄弟,但我需要的是页面上没有任何从上到下的边距/填充,它似乎永远不会起作用。不要紧,我遵循了代码中您所做的,并设法将其修复。谢谢你的帮助你很好
<body>
<div id="page" class="PageClass">
</div>
.PageClass {
{
**width: 100vw;**
background-color: rgba(255,255,255,0.7);
position: absolute;
/* you wanna take this of since it is not letting you make the page ful width and giving a 60px spaing on the left */ margin-left:60px;
margin-right:0px;
margin-bottom:0px;
padding:0px;
min-height:100vh;
}
}