BootStrap Div置中,bootstrapdiv置中

來源:互聯網
上載者:User

BootStrap Div置中,bootstrapdiv置中

使用BootStrap,如果一個Div只佔用了一小部分,怎麼置中呢?

<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><title>BootStrap3.3.2測試</title><link href="../bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet"><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"><script src="../Jquery/jquery-1.11.2.min.js"></script><script src="../bootstrap/3.3.2/js/bootstrap.min.js"></script><style>.col-center-block {    float: none;    display: block;    margin-left: auto;    margin-right: auto;}</style></head><body><div class="container">  <div class="row myCenter">    <div class="col-xs-6 col-md-4 col-center-block">      <form class="form-signin">        <h2 class="form-signin-heading">請登入</h2>        <label for="username" class="sr-only">使用者名稱</label>        <input type="text" id="username" class="form-control" placeholder="使用者名稱" required autofocus>        <label for="inputPassword" class="sr-only">密碼</label>        <input type="password" id="inputPassword" class="form-control" placeholder="密碼" required>        <div class="checkbox">          <label>            <input type="checkbox" value="remember-me">            記住我 </label>        </div>        <button class="btn btn-lg btn-primary btn-block" type="submit">登入</button>      </form>    </div>  </div></div></body></html>
給Div添加這樣一個Style就可以實現:

<style>.col-center-block {    float: none;    display: block;    margin-left: auto;    margin-right: auto;}</style>
最終效果如下:




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.