我是一名新手,注册是因为在现有的讨论中找不到我的答案。
我正在尝试制作一个单页网站,希望'落地页'具有全屏背景。我已经将背景放在整个页面上了,但当我开始在div中放置文本时,它就出问题了。我使用了以下css(sass):
.intro {
color: #fff;
height: 100vh;
background: url('http://www.flabber.nl/sites/default/files/archive/files/i-should-buy-a-boat.jpg') no-repeat center center;
background-size: cover;
&--buttons {
position: absolute;
bottom: 2em;
}
}
p.hello {
margin: 30px;
}
.page1 {
color: #fff;
height: 100vh;
background: beige;
}
.page2 {
color: #fff;
height: 100vh;
background: black;
}
使用以下HTML代码:
<html>
<head>
<link href="stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css" />
<title>My title</title>
</head>
<body>
<div class="container">
<div class="row">
<div id="intro" class="intro">
<div class="text-center">
<p class="hello">
Intro text is coming soon!
</p>
<div class="col small-col-12 intro--buttons">
<p>Buttons coming here.
</p>
</div>
</div>
</div>
<div id="page1" class="col col-12 page1">
<p>Tekst test</p>
</div>
<div id="page2" class="col col-12 page2">
<p>Tekst test.</p>
</div>
</div>
</div>
</body>
</html>
您可以在这里查看结果:http://codepen.io/Luchadora/full/waYzMZ 或者查看我的代码:http://codepen.io/Luchadora/pen/waYzMZ 正如您所看到的,当定位介绍文本 (
p.hello {margin: 30px;}
) 时,背景大小发生了变化,不再是全屏幕了。(顺便说一句:我使用了一个示例背景)。而且其他页面现在也有了白色空间。我该怎么解决这个问题呢?我已经阅读了关于视口的文章,但我认为我只需要使用
height: 100vh;
,对吗?谢谢!
{padding:1px;}
,这也有效。至少,在我的桌面版本上是这样,但在Codepen示例中不是。但现在我有一个水平滚动条,而且overflow-x:hidden
不起作用,我还在弄清楚那个问题。如果我将{padding:1px;}
放在p
或intro div
上,会有影响吗? - Luchadorabox-sizing:border-box
- 这意味着任何填充都将包含在宽度中。填充应该放在包装p
的元素上(或其任何父级元素上)。 - Peteoverflow-x:hidden
来修复它,作用于html
和body
两个元素。 - Luchadora