Is there a way to use media query on html? I need to put a image like a banner centralized on my page, when the screen it’s less than 768px it’s shows a smaller image but when the screen grows to more than 768px it should replace the smaller image to another image that I have that is bigger. Is there a way to make this only on html and inline css? I should’nt use an external file.
4
Answers
You can use a
div
which has abackground-image
instead of theimg
element. Then you can add a media query in CSS where you define a smaller size and a differentbackground-image
for the mobile version.You can achieve this using inline CSS:
If you have to do in one file, in html, it is not possible to do in img tag. But you can do something like this, using embedded style element. For example:
You don’t even have to use CSS for this. Use the
<picture>
element; it is widely supported by modern browsers:Try it: