尝试在每种类型的浏览器中居中设置页面——在大多数浏览器中有效,而在其他浏览器中无效



我为这个网站做了一组非常简单的html页面:http://www.soilexpress.com/environmental.php

在大多数设备上,它在浏览器窗口的大小内正确居中,两边的边距相等。

不过,我收到了一些关于特定问题机器的报告:

在ie10(大屏幕笔记本电脑)上,它看起来偏离了中心。

在iphone4G(纵向或横向)上,页面偏离了右侧的中心。

我想知道是否有人能告诉我设备/浏览器的特定行要放在顶部,这样它就会一直居中。

我认为问题来自于我在页面顶部识别(或缺少)文档类型,并认为也许我应该在顶部添加一些If语句,以便为某些浏览器提供更严格的文档类型????

现在,它仅被标识为html。如果我将描述更改为更详细的类型,它将更改居中。

我很感激你的帮助。谢谢


这是上面示例中的文本--environment.php

<html>
<head><title>Environmental - SoilExpress</title>
<link rel="shortcut icon" href="/favicon.ico">
<link href='http://fonts.googleapis.com/css?family=Lato:300,900' rel='stylesheet' type='text/css'>
<style type="text/css">
<!--
img { border-style: none;}
td {color:#ffffff; font-size:15px; font-family: 'Lato', sans-serif; font-weight: 300; }
.footer {color:#999999; font-size:12px; font-family: 'Lato', sans-serif; font-weight: 300; }
.whiteheader {color:#ffffff; font-size:20px; font-family: 'Lato', sans-serif; font-weight: 300; }
.redheaderblower {color:#cc0000; font-size:30px; font-family: 'Lato', sans-serif; float: right; font-weight: 900; }
.redheadereow {color:#ff0000; font-size:30px; font-family: 'Lato', sans-serif; float: left; font-weight: 900; }
-->
</style>
</head>
<body background='/web_images/level3-background.png' marginheight="0" topmargin="0">
<!-- master table -->
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td width='50%'><img src='/web_images/trs.gif' height='1' width='1'></td>
<td valign="top" width="1200">
<!-- content table -->
<table width="1200" cellpadding="0" cellspacing="0" border="0">
<tr>
<td valign="top" width="1200" colspan='6'>
<a href='/'>
<img src='/web_images/row-header.png' width='1200' height='120' style='vertical-align: top;'>
</a>
</td>
</tr>
<!-- ROW navigation -->
<tr>
<td>
<img src='/web_images/row-nav1.png' width='207' height='136' style='vertical-align: top;'>
</td>
<td>
<a href='/safety.php'>
<img src='/web_images/row-nav-safety.png' width='185' height='136' style='vertical-align: top;'>
</a>
</td>
<td>
<a href='/equipment.php'>
<img src='/web_images/row-nav-equipment.png' width='220' height='136' style='vertical-align: top;'>
</a>
</td>
<td>
<a href='/capable.php'>
<img src='/web_images/row-nav-capable.png' width='165' height='136' style='vertical-align: top;'>
</a>
</td>
<td>
<a href='/environmental.php'>
<img src='/web_images/row-nav-environmental.png' width='218' height='136' style='vertical-align: top;'>
</a>
</td>
<td>
<img src='/web_images/row-nav1.png' width='205' height='136' style='vertical-align: top;'>
</td>
</tr>
<tr>
<td valign="top" width="1200" colspan='6'>
<img src='/web_images/environmental.png' width='1200' height='750'>
</td>
</tr>
<tr>
<td valign="top" width="1200" colspan='6'>
<table width='1200' cellspacing='0' cellpadding='0' border='0'>
<tr><td bgcolor='black'>
<img src='/web_images/trs.gif' width='381' height='1'>
</td>
<td bgcolor='black'>
<a href='/contact.php'>
<img src='/web_images/footer-contact-link.png' width='123' height='92' style='vertical-align: top;'>
</a>
</td>
<td bgcolor='black'>
<a href='/'>
<img src='/web_images/footer-home-link.png' width='196' height='92' style='vertical-align: top;'>
</a>
</td>
<td bgcolor='black'>
<img src='/web_images/footer-copyright.png' width='500' height='92' style='vertical-align: top;'>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td><td width='50%'><img src='/web_images/trs.gif' height='1' width='1'></td>
</tr></table>
</body></html>
<span style="position:absolute;top:0px;left:0px;background-color:white;width:100%;font-family:Trebuchet MS,Liberation Sans,DejaVu Sans,sans-serif;font-size:20px;">
     <div align="center">
          <div style="width:980px;text-align:left;">
          /*Write within this and it will be centered*/
          </div>
     </div>
</span>

我只是在一小段代码中使用了div的内联CSS。

希望这正是你所需要的。

为ie10笔记本电脑设计。。。它们的屏幕宽度小于主图像的1200像素宽度。。。因此,它像正常情况一样在左侧显示,在右侧出血,使其看起来偏离了中心。

将中心图像设置为900像素宽,现在效果完美。

目前还不确定iphone5,但希望它也能正常工作。

我之所以选择直接使用老式的html与css,是因为整个页面只有两个图像。一个带有链接的页眉和一个正文图像。这意味着一旦我正确居中,它在每个浏览器上看起来都是一样的。如果我试图集中使用CSS,我会遇到版本问题。由于我没有真实的文本,没有一致的结果似乎是在浪费时间。

我感谢你的回复!将在另一个上使用:)

最新更新