css3 position fixed居中的问题
通常,我们要让某元素居中,会这样做:
#element{
margin:0 auto;
}
假设还想让此元素位置固定呢?一般我们会加入position:fixed,例如以下:
#element{
position:fixed;
margin:0 auto;
}
可是这样做的结果就是。元素不居中了。这说明fixed使对象脱离了正常文档流。
解决方式:
#element{
position:fixed;
margin:0 auto;
left:0;
right:0;
}
可是在IE7下面的版本号中无法工作,要将其更改为:
#element{
position:fixed;
margin:0 auto;
left:auto;
right:auto;
}
最后我们能够这样:
if ($.browser.msie && parseInt($.browser.version, 10) <= 7) {
strAlertWrapper.css({position:'fixed', bottom:'0', height:'auto', left:'auto', right:'auto'});
}
演示样例代码:http://jsfiddle.net/4Ly4B/33/
假设对你有帮助,欢迎增加:QQ群:124116463。一起讨论前端技术吧!
css3 position fixed居中的问题的更多相关文章
- position fixed 居中
1.水平居中.footer { height: 10%; text-align: center; position: relative; left: 50%; transform: translate ...
- position:fixed 居中问题
设置Css属性position:fixed后如何使这个盒子居中呢?其实也很简单: 就是需要设置给这个div盒子设置属性: left:0; right:0; margin:0 auto; ******* ...
- 关于position:fixed;的居中问题
通常情况下,我们通过操作margin来控制元素居中,代码如下: #name{ maigin:0px auto; } 但当我们把position设置为fixed时,例如: #id{ position:f ...
- css中position:fixed实现div居中
上下左右 居中 代码如下 复制代码 div{ position:fixed; margin:auto; left:0; right:0; top:0; bottom:0; width:200px; h ...
- position:fixed;如何居中
div{ position:fixed; margin:auto; left:; right:; top:; bottom:; width:100px; height:100px; } 如果只需要左右 ...
- position:fixed div如何居中
div{position:fixed;margin:auto;left:0; right:0; top:0; bottom:0;width:200px; height:150px;}
- day2-设置position:fixed/absolute无法使用margin:auto调整居中
问题描述:父元素给定宽度,子元素给定宽度,设置子元素position为absolute/fixed后,无法使用margin:auto使子元素在父元素中水平居中 html代码如下: <div cl ...
- 使用属性position:fixed的时候如何才能让div居中
css: .aa{ position: fixed; top: 200px; left: 0px; right: 0px; width: 200px; height: 200px; margin-le ...
- 元素设置position:fixed属性后IE下宽度无法100%延伸
元素设置position:fixed属性后IE下宽度无法100%延伸 IE bug 出现条件: 1.div1设置position:fixed属性,并且想要width:100%的效果. 2.div2(下 ...
随机推荐
- SQL 与或运算
如果一个字段需要同时包含多个信息点, 最佳的方法是进行位运算,如:1,2,4,8,16 根据与运算进行判断,如一个字段为7,判断2是否存在, 7&2 = 2为ture时,表示存在,反之亦然, ...
- [办公软件][2]screenToGif
https://github.com/NickeManarin/ScreenToGif/wiki/help 下载: .Net Framework 4.6.1 https://www.microso ...
- log4net配置分析
appender 附加器 RollingFileAppender 滚动文件appender MaxSizeRollBackups 最大尺寸回滚 ConversionPatter ...
- 【转】C# 中的"yield"使用
C# 中的"yield"使用 yield是C#为了简化遍历操作实现的语法糖,我们知道如果要要某个类型支持遍历就必须要实现系统接口IEnumerable,这个接口后续实现比较繁琐要写 ...
- Java中接口的作用
转载于:https://www.zhihu.com/question/20111251 困惑:例如我定义了一个接口,但是我在继承这个接口的类中还要写接口的实现方法,那我不如直接就在这个类中写实现方法岂 ...
- 【bzoj1014】[JSOI2008]火星人prefix Splay+Hash+二分
题目描述 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 7 8 9 10 ...
- MGW——美团点评高性能四层负载均衡
转自美团点评技术博客:https://tech.meituan.com/MGW.html 前言 在高速发展的移动互联网时代,负载均衡有着举足轻重的地位,它是应用流量的入口,对应用的可靠性和性能起着决定 ...
- Oracle学习记录1
1.current_date与sysdate区别 在oracle中current_date与sysdate都是显示当前系统时间, 其结果基本相同,但是有三点区别:a. current_date返回的是 ...
- Linux 之 Xunsearch(2)
Linux 之 Xunsearch(2) 参考教程:[千峰教育] Xunsearch的项目配置文件: 基本说明: (1)项目配置是一个项目的核心灵魂,非常重要,通常保存为.ini文件, 通常存储在/u ...
- serializeObject 的应用
function sendForm() { var invOrderModelWrapper = {}; // 头 var objHeader = $('#invOrderForm').seriali ...