Skip to content

Instantly share code, notes, and snippets.

@zhangolve
Last active November 18, 2024 15:38
Show Gist options
  • Save zhangolve/027e5fb74fd9e62331742e018b89b9f2 to your computer and use it in GitHub Desktop.
Save zhangolve/027e5fb74fd9e62331742e018b89b9f2 to your computer and use it in GitHub Desktop.
响应式背景图片全屏实现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;
}
// Full page responsive background image
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;
z-index: -1;
}
// Full page background color
div.admin-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;
z-index: -1;
background-color: $admin-bg;
}
@media screen and (max-width: 1024px) { /* Specific to this particular image */
img.bg {
left: 50%;
margin-left: -512px; /* 50% */
}
div.admin-bg {
left: 50%;
margin-left: -512px; /* 50% */
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment