BootStrap Div居中



使用BootStrap,如果一个Div只占用了一小部分,怎么居中呢?

  1. <!doctype html>  
  2. <html lang="zh-CN">  
  3. <head>  
  4. <meta charset="utf-8">  
  5. <title>BootStrap3.3.2测试</title>  
  6. <link href="../bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">  
  7. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">  
  8. <script src="../Jquery/jquery-1.11.2.min.js"></script>  
  9. <script src="../bootstrap/3.3.2/js/bootstrap.min.js"></script>  
  10. <style>  
  11. .col-center-block {  
  12.     float: none;  
  13.     display: block;  
  14.     margin-left: auto;  
  15.     margin-right: auto;  
  16. }  
  17. </style>  
  18. </head>  
  19.   
  20. <body>  
  21. <div class="container">  
  22.   <div class="row myCenter">  
  23.     <div class="col-xs-6 col-md-4 col-center-block">  
  24.       <form class="form-signin">  
  25.         <h2 class="form-signin-heading">请登录</h2>  
  26.         <label for="username" class="sr-only">用户名</label>  
  27.         <input type="text" id="username" class="form-control" placeholder="用户名" required autofocus>  
  28.         <label for="inputPassword" class="sr-only">密码</label>  
  29.         <input type="password" id="inputPassword" class="form-control" placeholder="密码" required>  
  30.         <div class="checkbox">  
  31.           <label>  
  32.             <input type="checkbox" value="remember-me">  
  33.             记住我 </label>  
  34.         </div>  
  35.         <button class="btn btn-lg btn-primary btn-block" type="submit">登录</button>  
  36.       </form>  
  37.     </div>  
  38.   </div>  
  39. </div>  
  40. </body>  
  41. </html>  
给Div添加这样一个Style就可以实现:

  1. <style>  
  2. .col-center-block {  
  3.     floatnone;  
  4.     displayblock;  
  5.     margin-leftauto;  
  6.     margin-rightauto;  
  7. }  
  8. </style>  
最终效果如下:



评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值