IE8 text-align: center Left-sided solution

Source: Internet
Author: User
Keywords Webpage making CSS tutorial
Tags application browsers css tutorial different display displays example problems

The application of text-align: center shows different effects in different browsers, this article shows different displays in IE7, IE8 and IE9, and solves the problem of left-deviation displayed in IE8.

In IE7 and some browsers interpreted as elements and text within the element are centered.

In IE8 and IE9, some browsers interpret that the text within the element is centered.

<div style = "border: 1px solid red; height: 150px; width: 150px; text-align: center;">
<div style = "border: 1px solid green; height: 100px; width: 100px;"> </ div>
Hello there
</ div>

Can be found in IE7, the elements use the text-align: center; After the div and the text are centered,

In IE8, the text within the element is centered, but the div element is not centered.

There are two solutions to this type of imbalance.

1 is ie7 tend to ie8, that is, ie7 also showed the effect of IE8, the element left home. The method is to add float: left on the element inside it

2 is so ie8 trend ie7 that is, ie8 also shows the effect of ie7, the element is centered. The method is to add margin: 0 auto inside the element; it's fine.

Related Article

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.