roa*_*oul 1 html php internet-explorer smarty character-encoding
我使用PHP Smarty时很奇怪.似乎php文件的编码会影响css.
PHP文件(ANSI) - test2.php
<?php
include_once("inc/smarty_inc.php");
$smarty->display('test.tpl.htm');
Run Code Online (Sandbox Code Playgroud)
Smarty文件(ANSI) - test.tpl.htm
<!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>
<title>JPR</title>
</head>
<body>
<div style="width:500px;height:200px; background-color:Red;margin:auto;">
test
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当这两个文件是ANSI时.div显示在页面的中心.(IE和Firefox)
当其中一个转换成utf-8时.div显示在页面左侧.(仅在IE中,可以使用Firefox)
它有什么关系?如何在IE中使用uff-8使其正常?
您使用 BOM 将文件保存为UTF-8 ,这会导致响应中的第一个字节为字节顺序标记的字节,而不是doctype.当IE首先看不到doctype时,它会转到quirks模式,其中box模型不同.
您需要将其转换为UTF-8 而不使用 BOM.这取决于您使用的文本编辑器或转换器.