首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >IE7下当position:fixed遇到text-align:center

IE7下当position:fixed遇到text-align:center

作者头像
菩提树下的杨过
发布2018-01-22 16:06:20
5160
发布2018-01-22 16:06:20
举报

啥也不说,先看代码:

<!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>IE7下当position:relative遇到text-align:center</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    <style type="text/css">
      body{padding:0;margin:0}      
      #wrap{text-align:center}
      #toolbar{width:100%;height:25px;background:#000;position:fixed;bottom:0;}
    </style>
</head>
<body>
 <div id="wrap"> 
 <div id="toolbar"></div>
 </div> 
</body>
</html>

运行代码

IE7(或IE8的兼容模式)下运行代码会发现,底部的toolbar栏,宽度只有一半了(FF,Chrome等浏览器能正常解析)

触发条件:

1.IE7/IE8兼容模式

2.position:fixed定位时,仅写了bottom或top,遗漏了right或left

3.position:fixed外层容器中使用了text-align:center

解决办法:

1.position:fixed对应元素的"外层容器"中的text-align:center去掉,或改成text-align:left即可

<!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>IE7下当position:relative遇到text-align:center</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    <style type="text/css">
      body{padding:0;margin:0}
      #wrap{text-align:left}
      #toolbar{width:100%;height:25px;background:#000;position:fixed;bottom:0;}
    </style>
</head>
<body>
 <div id="wrap"> 
 <div id="toolbar"></div>
 </div> 
</body>
</html>

运行代码

2.使用position:fixed时,同时将bottom与right定位写全,第一段代码中,遗漏了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>
    <title>IE7下当position:relative遇到text-align:center</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    <style type="text/css">
      body{padding:0;margin:0}
      #wrap{text-align:center}
      #toolbar{width:100%;height:25px;background:#000;position:fixed;bottom:0;right:0}
    </style>
</head>
<body>
 <div id="wrap"> 
 <div id="toolbar"></div>
 </div> 
</body>
</html>

运行代码

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2010-02-28 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档