如何居中div?如何居中一个浮动元素?
如何居中div?
给div设置一个宽度,然后添加margin:0 auto属性
div{ width:200px; margin:0 auto; }如何居中一个浮动元素?
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:html5="http://www.w3.org/html5/"> <head> <meta charset="utf-8" /> <meta http-equiv=”X-UA-Compatible” content=”IE=edge,chrome=1″/> <title></title> <style> .div { position: absolute; top: 50%; left: 50%; margin: -100px 0 0 -150px; width: 300px; height: 300px; border: 1px solid #008800; } </style> </head> <body> <div class="div"> 元素居中 </div> </body> </html>