F
F
faleaksey2019-03-18 11:07:57
css
faleaksey, 2019-03-18 11:07:57

What is the best way to center an image?

Hello! There are the following 2 options for centering the image https://jsfiddle.net/qc9pmb7k/ , the first option is bad because you have to set different values ​​for the width and height of the block with the image at different resolutions (if the block itself is adaptive), so that it is always centered. The second option eliminates all this (almost) but the question of accessibility arises. Is it worth adding aria attributes in this case, so that search engines understand that there should be an image there? what about title and alt in this case?
What are the alternative, as simple as possible solutions to cover the following 4 questions:
1) Accessibility
2) Adaptability
3) Simplicity of css
4) Cross-browser compatibility

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2019-03-18
@Kozack

If the image is part of the content, only the <img alt="">. If the image performs an exclusively decorative role, then the background.

A
andrash_, 2019-03-18
@andrashsh

at the parent:

display flex;
justify-content: center; 
align-items: center;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question