Reputation: 101
here is the problem I faced and I wondering any other efficient way to solve it. Recently I develop a e-commerce website. This website is a reponsive website.
What I done:
Question:
Thanks.
Upvotes: 0
Views: 556
Reputation: 2898
Here's one way to display different images without using two divs. The browser will only load the image appropriate to the screen size determined in the media - attribute. Open the snippet in full page and decrease the size of the browser window to see the result.
<picture>
<source media="(min-width: 487px)" srcset="http://via.placeholder.com/350x150">
<source media="(max-width: 486px)" srcset="http://via.placeholder.com/150x150">
<img src="http://via.placeholder.com/350x150" style="width:auto;">
</picture>
This can also be done only using srcset:
<img srcset="http://via.placeholder.com/350x150 776w,
http://via.placeholder.com/150x150 486w">
You can get more information about responsive images at MDN.
Upvotes: 0
Reputation: 101
This is what I get. But this method also required two image. But no need pre-load two image in two div.
Upvotes: 0