I'm having some trouble aligning a main image. It should be center-aligned horizontally, yet keeps going all over the place. The page can be found here http://0034.eu/propmanager/
<img src="images/background-space.png" class="displayed" border="0" />
IMG.displayed{
display: inline-block;
margin-left: auto;
margin-right: auto;
}
That's basically the CSS I have applied to the image, all the source code is on main index.html (no separate style sheet).
To center an image horizontally, you can use the CSS text-align property. Step 1: Since this property only works on block-level elements and not inline elements, let's start by wrapping the image in a block element.
Aligning an image means to position the image at center, left and right. We can use the float property and text-align property for the alignment of images. If the image is in the div element, then we can use the text-align property for aligning the image in the div.
Center CSS Image Vertically and Horizontally We can use flex-box to center an image horizontally and vertically. To do so we must use both the justify-content and align-items property on the parent container of the image.
Add this to your CSS style.
img.displayed {
display: table-caption;
margin: 0 auto;
}
EDIT
From the inputs of IlyaStreltsyn, I agree with the point of clearing
the right
with display:block
for the image to be centered.
For Instance,
img.displayed {
display: block;
margin: 0 auto;
clear: right;
}
Add display: block;
img.displayed{
display: block;
margin:0 auto;
}
DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With