首页自适应背景图,不用 js 实现高度为浏览器可见高度?

2014 年 12 月 16 日
 fyh1807008
载入的首页大图正好height是浏览器的高,看了下代码感觉不是js算出来的,用css怎么实现?
例子: https://bitcoinfoundation.org/
3908 次点击
所在节点    问与答
14 条回复
wolfan
2014 年 12 月 16 日
min-height:100%
么?
ihuguowei
2014 年 12 月 16 日
background-size:cover
JoyNeop
2014 年 12 月 16 日
lemonda
2014 年 12 月 16 日
.home .site-header .bg-image {
background-image: url("../img/bitcoin-bg-1.jpg");
background-position: center center;
background-size: cover;
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
z-index: 1;
}
txlty
2014 年 12 月 16 日
测试的姿势不对。
把JS禁用,再看,效果没了。
pandada8
2014 年 12 月 16 日
height:100vh
linking
2014 年 12 月 16 日
@txlty you're right
lvwzhen
2014 年 12 月 16 日
100vh 才是对的
Slienc7
2014 年 12 月 16 日
body {
margin:0;
padding:0;
background: #000 url('imgs.jpg') center center fixed no-repeat;
-moz-background-size: cover;
background-size: cover;
}
ooh
2014 年 12 月 17 日
body {
background: url(../img/bg.png) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
Doubear
2014 年 12 月 17 日
楼上那么多答案 到底哪个是正确的啊?
Grenadn
2014 年 12 月 17 日
需要把html元素和body元素设为height:100%,然后给body加上background,把它的background-size设为cover,over
kmvan
2014 年 12 月 17 日
这网站。。。居然是“沉浸式”顶栏。。。
fyh1807008
2014 年 12 月 17 日
正解 @JoyNeop
vh赞

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/154433

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX