Last active
November 18, 2024 15:38
-
-
Save zhangolve/027e5fb74fd9e62331742e018b89b9f2 to your computer and use it in GitHub Desktop.
响应式背景图片全屏实现css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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