0
Image center
Hey. I wanted to ask who knows. Is it possible to place the image in the center (in CSS)? And if yes than how?
4 Respostas
+ 11
Coder Avoid <center> as it is a legacy tag and isn't a good practice to use any longer. Always apply design and layout specifications using CSS.
Never use style HTML tags like <b>, <i>, <u>, <font>, <center>, etc for anything as these are from the days of past. 😉
In CSS, learn about what the others have suggested with setting the left and right margins to auto. That is going to be your friend. 😉
img {
display: block;
margin: 0 auto;
}
NOTE: The style rule above for margin is equivalent to the expanded version below:
margin-top: 0;
margin-right: auto;
margin-bottom: 0;
margin-left: auto;
+ 4
use the image as backgound using background-image
then set its background-position to center
+ 4
CSS Pro Tips: Centering Elements by Domino
https://www.sololearn.com/post/37760/?ref=app
+ 3
Denis Alexandrovich Fandeev if you're referring to background image
body {
background: #fff url(img.jpg) center center / contain no-repeat;
}
https://code.sololearn.com/WO8vn04KCK1a/?ref=app