I'm trying to change the image src depending on the screen size using media queries. I tried background:url(x); but it didn't work. I read somewhere that I should use content:url(x) instead, but when I do so, I get a blank page. Can anyone tell me what's wrong with my code?
HTML:
<div class="container" id="at-header">
<img class="image" id="logo" src="img/logo_white.png" />
<img class="image" id="main-img" src="img/desktop_homepage.jpg" />
</div>
CSS:
@media screen and (max-width: 767px){
#main-img{
content:url("img/mobile_homepage.jpg");
}
}
@media screen and (min-width: 768px) {
#main-img{
content:url("img/tablet_homepage.jpg");
}
}
@media (min-width: 992px){
#main-img{
content:url("img/desktop_homepage.jpg");
}
}
@media (min-width: 1200px) {
#main-img{
content:url("img/desktop_homepage.jpg");
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…