html - Background images not loading when used in media queries -
i have pretty standard mvc template i'm using project. on view in project, trying display different background image depending on screen width. problem if wrap css in media queries push content development server, background images don't load. don't have problem in localhost though. i'm using bootstrap in project, particular css written in separate file. also, project sits in project on server.
/root project --my project css:
html { background: url(/images/img1.jpg) no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; -ms-background-size: cover; background-size: cover; } @media (max-width: 768px) { html { background: url(/images/img2.jpg) no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; -ms-background-size: cover; background-size: cover; } .center-margin { margin-top: 30%; } .header-text { color: black; } } the header in html has following metadata tags:
<head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"> @styles.render("~/content/css") @scripts.render("~/bundles/modernizr") </head> after took media query off first html block in css, started displaying again. second block wrapped in media query won't display. other css inside media query displays, background image giving me issues.
your code working. should make sure image resources uploaded server in correct directory. also, typically loading urls you're going want put them in quotes.
html { background: url("http://www.joomlaworks.net/images/demos/galleries/abstract/7.jpg") no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; -ms-background-size: cover; background-size: cover; } @media (max-width: 768px) { htm l { background: url("http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg") no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; -ms-background-size: cover; background-size: cover; } .center-margin { margin-top: 30%; } .header-text { color: black; } } here codepen of working images hosted online.
Comments
Post a Comment