D
D
darksladen2017-10-12 22:18:24
css
darksladen, 2017-10-12 22:18:24

How to make a responsive image in a block?

What is the best way to make responsive images?
Recently I got acquainted with this method: after loading the page, make images the background, and delete img. Everything seems to be cool, but how will this affect indexing .. And in general, does anyone do this?
https://codepen.io/anon/pen/NaBEgb

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Ankhena, 2017-10-13
@Ankhena

1. There is a tag <picture>to show different images on different screens
2. height: auto for proportions
3. positioning
4. object-fit for proper cropping, similar to bg size.
About the fact that pictures can be prepared in advance of the correct proportions, it is better to keep silent.
In the presence of all this, it is not clear why the manipulation of turning pictures into a background is needed. Unless someone knows js better than css.

V
Voll., 2017-10-13
@vollthegreat

try <picture> tag under screen dimensions...

E
Entoni12, 2017-10-12
@Entoni12

Try setting the picture sizes to "vh" and "vw".

G
Georgy Volokitin, 2017-10-19
@saintgeo23

If you know the dimensions of the image, you can do this:
1. give the block position: relative and choose (does not matter) padding-top or padding-bottom as a percentage (image height / image width * 100)
2. absolutely position another block inside ( all coordinates by zeros)
3. put a picture inside the absolute block width: 100%

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question