html - 尝试在每种类型的浏览器中将页面居中——在大多数情况下都有效,但在其他浏览器中无效

标签 html css

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

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

虽然我收到了一些关于特定问题机器的报告:

在 ie10(大屏幕笔记本电脑)上,它看起来偏向右侧。

在 iPhone 4G(纵向或横向)上,页面偏向右侧。

我想知道是否有人可以告诉我将特定于设备/浏览器的行放在顶部以便它始终居中。

我认为问题出在我对页面顶部文档类型的识别(或缺乏),我想也许我应该在顶部添加一些 If 语句以允许某些浏览器使用更严格的文档类型? ???

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

感谢您的帮助。谢谢。


这是上面示例中的文本 -- environmental.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>

我只是将内联 CSS 用于 div 的代码行很少。

希望这就是您所需要的。

关于html - 尝试在每种类型的浏览器中将页面居中——在大多数情况下都有效,但在其他浏览器中无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20089121/

相关文章:

html - 设置确认框尺寸

css - 使用点击/点击事件禁用 CSS3 延迟转换

css - JavaFX 样式化相同类型的所有节点,例如 VBox

html - 如何防止 Bootstrap Navbar 将品牌堆叠在菜单顶部?

javascript - 在这种情况下,如何将数据从 html 传输到 php

javascript - 表单代码上的颜色更改文本验证问题

javascript - 使输入转到 div 的底部

css - HTML (5) 列的定位问题

javascript - 在移动设备中打开/关闭导航栏。错误 : Cannot read parentnode of undefined

jquery - 分别为每个 li 添加一个 child