Tom*_*ers 48 css fullscreen responsive-design zurb-foundation
我是前端开发和基金会的新手.
我试图<div class="main-header">成为一个响应缩小的全屏图像.
谁能告诉我我做错了什么?它正在缩放,但没有显示完整的图像.我也想让<div class="large-6 large-offset-6 columns">它坐在移动设备上面 - 这可能吗?
HTML:
<!-- MAIN HEADER -->
<div class="main-header">
<div class="row">
<div class="large-6 large-offset-6 columns">
<h1 class="logo">BleepBleeps</h1>
<h3>A family of little friends<br>that make parenting easier</h3>
</div> <!-- END large-6 large-offset-6 columns -->
</div><!-- END ROW -->
</div><!-- END MAIN-HEADER -->
Run Code Online (Sandbox Code Playgroud)
CSS:
.main-header {
background-image: url(../img/bb-background2.png);
background-repeat: no-repeat;
background-position: center;
background-size: cover;
width: 100%;
height: 100%;
}
h1.logo {
text-indent: -9999px;
height:115px;
margin-top: 10%;
}
Run Code Online (Sandbox Code Playgroud)
Plu*_*mer 90
http://css-tricks.com/perfect-full-page-background-image/
//HTML
<img src="images/bg.jpg" id="bg" alt="">
//CSS
#bg {
position: fixed;
top: 0;
left: 0;
/* Preserve aspet ratio */
min-width: 100%;
min-height: 100%;
}
Run Code Online (Sandbox Code Playgroud)
要么
img.bg {
/* Set rules to fill background */
min-height: 100%;
min-width: 1024px;
/* Set up proportionate scaling */
width: 100%;
height: auto;
/* Set up positioning */
position: fixed;
top: 0;
left: 0;
}
@media screen and (max-width: 1024px) { /* Specific to this particular image */
img.bg {
left: 50%;
margin-left: -512px; /* 50% */
}
}
Run Code Online (Sandbox Code Playgroud)
要么
//HTML
<img src="images/bg.jpg" id="bg" alt="">
//CSS
#bg { position: fixed; top: 0; left: 0; }
.bgwidth { width: 100%; }
.bgheight { height: 100%; }
//jQuery
$(window).load(function() {
var theWindow = $(window),
$bg = $("#bg"),
aspectRatio = $bg.width() / $bg.height();
function resizeBg() {
if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
$bg
.removeClass()
.addClass('bgheight');
} else {
$bg
.removeClass()
.addClass('bgwidth');
}
}
theWindow.resize(resizeBg).trigger("resize");
});
Run Code Online (Sandbox Code Playgroud)
9pi*_*xle 25
<style type="text/css">
html {
background: url(images/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
</style>
Run Code Online (Sandbox Code Playgroud)
关于"background-size:cover"解决方案的一个提示,你必须把它放在"后台"定义之后,否则它将无法工作,例如这不起作用:
html, body {
height: 100%;
background-size: cover;
background:url("http://i.imgur.com/aZO5Kolb.jpg") no-repeat center center fixed;
}
Run Code Online (Sandbox Code Playgroud)
我个人不建议在 HTML 标签上应用样式,它可能会在开发后期的某个地方产生影响。
所以我个人建议将 background-image 属性应用于 body 标签。
body{
width:100%;
height: 100%;
background-image: url("./images/bg.jpg");
background-position: center;
background-size: 100% 100%;
background-repeat: no-repeat;
}
Run Code Online (Sandbox Code Playgroud)
这个简单的技巧解决了我的问题。这适用于大多数较大/较小的屏幕。
有很多方法可以做到,我发现这种方法更简单,后遗症最少
小智 6
我的发布前网站EnGrip遇到了同样的问题.我接受了这个问题.但经过几次试验后,这对我有用:
background-size: cover;
background-repeat: no-repeat;
position: fixed;
background-attachment: scroll;
background-position: 50% 50%;
top: 0;
right: 0;
bottom: 0;
left: 0;
content: "";
z-index: 0;
Run Code Online (Sandbox Code Playgroud)
纯CSS解决方案.我这里没有任何JS/JQuery修复.甚至是这个UI开发的新手.我以为我会分享一个有效的解决方案,因为我昨天读了这个帖子.
小智 5
用于全屏响应式背景图像
设置CSS高度(height:100vh)
例如:
.main-header {
background-image: url(../img/bb-background2.png);
background-repeat: no-repeat;
background-position: center;
background-size: cover;
width: 100%;
height:100vh; /* responsive height */
}
Run Code Online (Sandbox Code Playgroud)