我在HTML渲染IE7时遇到问题。
当将“margin:auto”块与“float:right”块组合时。
以下是此问题的示例代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<div id="floating" style="float: right; background-color: #ccf">
This is the top right links block
</div>
<div id="body" style="width: 800px; margin: auto; background-color: #fcc">
This is the body.
This is the body.
This is the body.
This is the body.
This is the body.
This is the body.
This is the body.
This is the body.
This is the body.
This is the body.
</div>
</body>
在IE7中出现的问题:
- margin:auto不能使"body"块居中。它似乎受到"floating"块的影响。 - 当折叠时,"floating"块实际上并没有浮动到"body"上面。
在IE7中的表现:
- "body"块没有居中,如下图所示:
![div "body" is not centered](https://istack.dev59.com/L4oRP.webp)
![div "floating" do not float](https://istack.dev59.com/mdv3h.webp)
- "body"块居中,如下图所示:
![div "body" correctly centered](https://istack.dev59.com/HIk4h.webp)
![div "floating" correctly floating](https://istack.dev59.com/UnnVC.webp)
谢谢!