Why does text-align
center text and images?
CSS:
#SupplierContainer {
width: 100%;
margin: 0 auto;
background-color: Blue;
}
#SupplierContainerContentHolder {
background-color: Yellow;
text-align: center;
}
HTML:
<div id="SupplierContainer">
<div id="SupplierContainerContentHolder">
<img src="~/Shared/Suppliers/Default" alt="Suppliers: [name removed]." />
<br />
<p>View a complete list of our Suppliers.</p>
</div>
</div>
Select the text that you want to center, and then click Paragraph on the Format menu. On the Indents and Spacing tab, change the setting in the Alignment box to Centered, and then click OK.
In general, you cannot use the CSS text-align property to center an image, as it works only on block elements, and the <img> is an inline one.
This is because text-align:center only affects inline elements, and <aside> is not an inline element by default. It is a block-level element. To align it, we will have to use something other than text-align , or turn it into an inline element.
Select the text that you want to center. in the Page Setup group, and then click the Layout tab. In the Vertical alignment box, click Center. In the Apply to box, click Selected text, and then click OK.
From W3,
This property describes how inline-level content of a block container is aligned.
Since <img>
is an inline-block element, this property applies to <img>
as well.
Have a look at the <img> tag, where it is stated :
The IMG element has no content; it is usually replaced inline by the image designated by the src attribute, the exception being for left or right-aligned images that are "floated" out of line.
Because text-align is used to align inline elements (not just text) inside the content area of an element. If you want the image not to be affected by the "text-align", float it then:
#SupplierContainerContentHolder img { float:left }
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