Answer the question
In order to leave comments, you need to log in
How to use the picture tag when creating responsive images?
Hello friends!
Comprehension of the zen of adaptive layout, it was necessary to go to the picture element ... After reading the docks about it, I had a question. We have 3 types of devices to adapt the design to them. This is a mobile phone, tablets and PC. But if for a PC I know what image size to display (this is the maximum), then for mobile phones and tablets I have a question.
How do you decide in practice what image size to take to display it for mobile phones and tablets, given the fact that this size will be multiplied later, for example, for retina devices and so on.
Please help, I've broken my head already...
Answer the question
In order to leave comments, you need to log in
We start the picture tag inside which we specify the default picture:
<picture>
<img class="image"
src="img/mobile.jpg"
alt="Описание" width="260" height="260">
<picture>
"img/mobile.jpg"
. <picture>
<source srcset="img/mobile.webp"
type="image/webp">
<img class="image"
src="img/mobile.jpg"
alt="Описание" width="260" height="260">
<picture>
img/mobile.webp
. <picture>
<source media="(min-width:768px)"
srcset="img/desktop.webp"
type="image/webp">
<source media="(min-width:768px)"
srcset="img/picture/desktop.jpg">
<source srcset="img/mobile.webp"
type="image/webp">
<img class="image"
src="img/mobile.jpg"
alt="Описание" width="260" height="260">
<picture>
768px
and the browser supports webp - it loads desktop.webp
, if it doesn't support it - desktop.jpg
. [email protected]
(260x260px). plus the same pictures, but 2 times higher resolution:[email protected]
(520x520px). The browser will decide whether to load them or not, based on the data on the pixel density on the screen received from the system (this is also a separate topic for discussion, there are articles titled something like "A pixel is not really a pixel." I don’t remember the exact name, but the meaning is that on the "so-called" Retina displays at the actual resolution, for example, 2500x1600px, the browser will "think" that the window is 1250px wide). In short, for "retinization" the code needs to be changed like this:<picture>
<source media="(min-width:768px)"
srcset="img/[email protected], img/webp/[email protected] 2x"
type="image/webp">
<source media="(min-width:768px)"
srcset="img/picture/[email protected], img/picture/[email protected] 2x">
<source srcset="img/webp/[email protected], img/webp/[email protected] 2x"
type="image/webp">
<img class="image"
src="img/[email protected]"
srcset="img/[email protected] 2x"
alt="Описание" width="260" height="260">
</picture>
<source>
[email protected]
[email protected]
It depends on your network.
Let's say you have 3 breakpoints: 0-767, 768 - 1199, 1200+ You take
3 pictures with a width of 768, 1200 and a maximum, respectively
oh dude... https://html5book.ru/images-in-html have fun
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question