怎么让div主体内容在屏幕中布局居中?
一样平常网页主体不论宽屏照旧窄屏幕是居中的,而主体居中症结点是最外层DIV组织居中来实现。最外层div屏幕中居中了,自然内容在此居中DIV内整体是居中的。
最外层DIV盒子屏幕中居中,很简单就需求对其设置margin:0 auto样式,同时最外层DIV不运用float浮动属性即可实现组织居中。
完善让div在屏幕中居中CSS代码:
body{ text-align:center} #main{ margin:0 auto}html body内代码:
<div id=”main”></div>完整居中实例DIV CSS代码:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>div主体在屏幕居中</title> <style> body{ text-align:center} #main{ margin:0 auto; width:300px;border:2px solid #00F} </style> </head> <body> <div id="main"> 看到DIV居中造诣,<br> 设置装备摆设静止宽度与边框 </div> </body> </html>成绩截图:
岂论屏幕大小div一直完成居中总结:切实这篇标题与教程文章,便是让DIV组织居中的完成。
如需转载,请注明文章出处和来源网址:http://www.divcss5.com/css-tool/t53157.shtml