div盒子在页面中水平垂直居中的几种方法。
来源:互联网 发布:java socket拒绝ip连接 编辑:程序博客网 时间:2024/04/24 06:51
方法一:设置绝对定位absolute,然后margin为自动
<html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <style type="text/css"> #container { width: 600px; height: 500px; border: 1px solid #000; margin:auto; position:absolute; background-color: #0096e6; left:0; right:0; bottom:0; top:0; } </style></head><body> <div id="container"> </div></body></html>
方法二:用了绝对定位position:absolute,使用left和top设置对象距离上和左为50%,但如果设置50%,实际上盒子是没有实现居中效果,所以又设置margin-left:-200px;margin-top:-100px。
<!DOCTYPE html><html><head> <meta charset="utf-8" /> <title>上下垂直居中 blhere</title> <style> #main {position: absolute; width:400px; height:200px; left:50%; top:50%; margin-left:-200px; margin-top:-100px; border:1px solid #00F; background-color: antiquewhite; } </style><body><div id="main">DIV水平居中和上下垂直居中</div></body></html>
阅读全文
1 0
- div盒子在页面中水平垂直居中的几种方法。
- div盒子水平居中垂直居中的几种方法
- div盒子水平垂直居中的方法
- div盒子水平垂直居中的方法
- div盒子水平垂直居中的方法
- 实现div水平、垂直居中的几种方法
- 让DIV水平和垂直居中的几种方法
- div垂直和水平居中的几种方法
- 未知宽高的img在已知宽高的div中水平垂直居中的几种方法
- html中div如何水平和垂直居中的几种css方法代码
- 水平垂直居中的几种方法
- 水平垂直居中的几种方法
- JS实现在不知道盒子宽高的情况下,默认让盒子在页面中水平垂直居中
- css 几种水平垂直居中的方法 及 弹性盒子
- <img>等标签在指定容器中水平垂直居中的几种实现方法
- 一个盒子在另一个盒子中垂直居中的方法
- 在DIV中图片垂直、水平居中(最简单方法)
- div 垂直 居中的几种 方法
- java.lang.NoClassDefFoundError:could not initial class xxxxxxxxx
- 使用Composer管理项目第三方库文件
- C
- Windows HLK
- A
- div盒子在页面中水平垂直居中的几种方法。
- linux c/c++判断文件夹文件个数(或者说是否为空)
- SpringMvc与Mongodb搭建
- spark hive 运行Exception
- List remove操作注意问题
- Azkaban3.0安装部署以及汉化
- 简述STL-->空间配置器
- 292. Nim Game
- ISO之日历的使用