css中position:fixed实现div居中
来源:互联网 发布:自定义端口 编辑:程序博客网 时间:2024/05/16 14:26
上下左右 居中
代码如下 复制代码
div{
position:fixed;
margin:auto;
left:0;
right:0;
top:0;
bottom:0;
width:200px;
height:150px;
}
如果只需要左右居中,那么把 bottom:0; 或者 top:0; 删掉即可
如果只需要上下居中,那么把 left:0; 或者 right:0; 即可
下面附一个DIV 元素在浏览器窗口居中
其实,实现这个效果并不复杂,利用 CSS 中的 position 定位就可以轻松搞定了。来看看代码吧:
代码如下 复制代码
<style type="text/css">
.dialog{
position: fixed;
_position:absolute;
z-index:1;
top: 50%;
left: 50%;
margin: -141px 0 0 -201px;
width: 400px;
height:280px;
border:1px solid #CCC;
line-height: 280px;
text-align:center;
fon(www.111cn.net)t-size: 14px;
background-color:#F4F4F4;
overflow:hidden;
}
</style>
<div class="dialog">我是在窗口正中央的,呵呵!</div>
设置的技巧全部在这里:
代码如下 复制代码
.dialog{
position: fixed;
_position:absolute; /* hack for IE6 */
z-index:1;
top: 50%;
left: 50%;
margin: -141px 0 0 -201px;
width: 400px;
height:280px;
border:1px solid #CCC;
line-height: 280px;
text-align:center;
font-size: 14px;
background-color:#F4F4F4;
overflow:hidden;
}
设置 position: fixed; _position:absolute;
设置 left:50% 和 top:50%;
设置 margin: -(DIV的offsetWidth/2) 0 0 -(DIV的offsetHeight/2)
from:http://www.111cn.net/cssdiv/css/62281.htm
代码如下 复制代码
div{
position:fixed;
margin:auto;
left:0;
right:0;
top:0;
bottom:0;
width:200px;
height:150px;
}
如果只需要左右居中,那么把 bottom:0; 或者 top:0; 删掉即可
如果只需要上下居中,那么把 left:0; 或者 right:0; 即可
下面附一个DIV 元素在浏览器窗口居中
其实,实现这个效果并不复杂,利用 CSS 中的 position 定位就可以轻松搞定了。来看看代码吧:
代码如下 复制代码
<style type="text/css">
.dialog{
position: fixed;
_position:absolute;
z-index:1;
top: 50%;
left: 50%;
margin: -141px 0 0 -201px;
width: 400px;
height:280px;
border:1px solid #CCC;
line-height: 280px;
text-align:center;
fon(www.111cn.net)t-size: 14px;
background-color:#F4F4F4;
overflow:hidden;
}
</style>
<div class="dialog">我是在窗口正中央的,呵呵!</div>
设置的技巧全部在这里:
代码如下 复制代码
.dialog{
position: fixed;
_position:absolute; /* hack for IE6 */
z-index:1;
top: 50%;
left: 50%;
margin: -141px 0 0 -201px;
width: 400px;
height:280px;
border:1px solid #CCC;
line-height: 280px;
text-align:center;
font-size: 14px;
background-color:#F4F4F4;
overflow:hidden;
}
设置 position: fixed; _position:absolute;
设置 left:50% 和 top:50%;
设置 margin: -(DIV的offsetWidth/2) 0 0 -(DIV的offsetHeight/2)
from:http://www.111cn.net/cssdiv/css/62281.htm
0 0
- css中position:fixed实现div居中
- [转]css中position:fixed实现div居中
- CSS中position:fixed实现div居中及div内元素实现居中的方法
- position:fixed div 居中
- fixed 实现div居中
- css中position:fixed;
- 使position:fixed的DIV居中
- css position: fixed; 垂直居中,绝对定位居中
- CSS中div布局position以及水平居中
- 使用属性position:fixed的时候如何才能让div居中
- CSS、HTMl使用position: fixed;实现div的高度填满剩余空间
- CSS中position:fixed的用法
- CSS 中 position:fixed 属性应用
- 实现DIV居中 css
- CSS实现div居中
- CSS div居中实现
- CSS中DIV居中
- css中absolute使用,用position和transform是div里面的div垂直居中
- schema的聚合。
- hdu 5055
- 软考——计算机系统知识
- friend ostream& operator < <
- 【深信服面试题】编写函数:1-1000之中包含2的个数,比如22算两个。
- css中position:fixed实现div居中
- 获取 trace 文件名词的脚本
- 我的android开发学习之路
- ListView的性能优化之convertView和viewHolder
- Lua的模块编写与module函数
- C/C++中的宏
- 关于qsort的用法
- CTRL+A, CTRL+C, CTRL+V
- hdu 5054