html让div居中的方法:1、通过加“内容”标签让div居中;2、在div中加入“margin:0 auto属性;”自动调节居中。
本文操作环境:windows7系统、HTML5&&CSS3版、Dell G3电脑。
DIV居中提供两个方法:
1、简单快捷方法就是加
示例:
立即学习“前端免费学习笔记(深入)”;
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>center居中</title> </head> <body> <center> <div>我要居中啦</div> </center> </body> </html>
2、div中加入margin:0 auto属性;自动调节居中。
示例2:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>margin居中</title> <style type="text/css"> .d1{ border:1px solid red; width:200px; height:200px; text-align:center; line-height:40px; margin:0 auto; } </style> </head> <body> <div class="d1"> 我是div,我居中啦... </div> </body> </html>
以上就是html怎样让div居中的详细内容,更多请关注php中文网其它相关文章!
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号