我用HTML和CSS编写了大约6个月的代码,我需要居中3个div,高度和宽度分别为100px和border-radius%100
使用jquery你可以设置你想要的 .
尝试这样的事情:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <script type="text/javascript" src="jquery-1.8.3.js"></script> <style> .wrap { text-align: center; } div div {width: 100px; height: 100px; background: #30353b; border-radius: 100%; display: inline-block;} </style> </head> <body> <div class="wrap"> <div></div> <div></div> <div></div> </div> <script type="text/javascript"> $(document).ready(function(){ var windowH = $( document ).height(); var divH = $('.wrap').height(); var result = (windowH-divH)/2; $('.wrap').css({'margin-top':result}); }) </script> </body> </html>
一种方法:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <style> .wrap {text-align: center;} div div {width: 100px; height: 100px; background: #30353b; border-radius: 100%; display: inline-block;} </style> </head> <body> <div class="wrap"> <div></div> <div></div> <div></div> </div> </body> </html>
或者垂直居中......
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <style> .wrap {display: table; position: absolute; top: 50%; left: 50%; margin: -50px 0 0 -150px;} div div {width: 100px; height: 100px; background: #30353b; border-radius: 100%; display: inline-block;} </style> </head> <body> <div class="wrap"> <div></div> <div></div> <div></div> </div> </body> </html>
干得好:
.wrap { text-align: center; position:absolute; margin:auto; left:0; right:0; top:0; bottom:0; width:100%; height:100px; display:block; } div div {width: 100px; height: 100px; background: #30353b; border-radius: 100%; display:inline-block; }
http://jsfiddle.net/drukaman/paohy1bc/
3 回答
使用jquery你可以设置你想要的 .
尝试这样的事情:
一种方法:
或者垂直居中......
干得好:
http://jsfiddle.net/drukaman/paohy1bc/