HTML关于居中的问题
2017-08-25 14:41
274 查看
1: margin:0 auto;方式–>设置当前层在父级层中居中
2: 定位方式
3: 水平居中
4: 垂直居中
5: 水平垂直居中
6: 文字居中text-align、line-height
文字在div中左右居中:
text-align:center
文字在div中垂直居中:
line-height值为外边框的高度
7: 图片居中vertical-align
可设置图片
vertical-align:middle
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> body{ text-align: center; } #box{ width: 720px; height: 250px; margin: 0 auto; border: 1px solid #FF0000; } </style> </head> <body> <div id="box"></div> </body> </html>
2: 定位方式
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> #box{ width: 720px; height: 250px; position: relative; left: 50%; margin-left: -360px; border: 1px solid #FF0000; } </style> </head> <body> <div id="box"></div> </body> </html>
3: 水平居中
.test1 ul { margin: 0 auto; }
4: 垂直居中
.test2 { position: relative; } .test2 ul { position: absolute; left: 0; top: 50%; transform: translate(0, -50%); }
5: 水平垂直居中
.test3 { position: relative; } .test3 ul { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
6: 文字居中text-align、line-height
文字在div中左右居中:
text-align:center
文字在div中垂直居中:
line-height值为外边框的高度
7: 图片居中vertical-align
可设置图片
vertical-align:middle
相关文章推荐
- 关于HTML里用margin居中的问题
- 关于html水平垂直居中的问题小结
- 关于html中 居中 问题小结
- 关于HTML中onchange事件与onkeyup事件的冲突问题
- 关于HTML界面改为aspx页面时CSS失效的问题
- 关于HTML中文乱码问题
- 关于springmvc配置html和jsp两种视图解析器所出现的问题
- HTML中关于图片与图片之间的缝隙问题
- 关于HTML页面接收前页面传值,并将值传给下一个页面的问题
- 关于浮动居中与清除浮动的问题
- 关于Android使用TextView+ImageSpan同一行文字图片居中的问题
- 关于Android加载html代码出现的问题
- 关于angular。js+ionic框架解析HTML结构的问题
- html页面中关于一个table表格中设置上下2个td宽度一致的问题
- 关于在WORD中MathType编辑公式居中及编号右对齐问题的解决办法
- 关于jsp include引用HTML乱码问题
- 关于IE和火狐,谷歌,Safari对Html标签Object和Embed的支持问题
- 解决ext htmleditor 回车,或者居中,设置一下字体颜色,就信息保存失败问题
- 关于txt文本的内容与html页面上显示的内容格式一致的问题
- 关于子DIV居中的问题