[ASP.NET MVC] 使用Bootstrap套件

來源:互聯網
上載者:User

標籤:style   blog   http   ar   使用   java   sp   資料   div   

[ASP.NET MVC] 使用Bootstrap套件前言

在開發Web項目的時候,除了一些天賦異稟的開發人員之外,大多數的開發人員應該都跟我一樣,對於如何建構出「美觀」的使用者介面而感到困擾。這時除了,加入美術人員這個選項之外,開發人員也可以自立自強,為Web項目內加入Bootstrap套件。透過使用Bootstrap套件中各種設計精美的樣式、組件,來讓Web項目的使用者介面更加的美觀大氣,增加客戶對於項目產出的好感度。本篇文章介紹如何在Web項目裡使用Bootstrap套件,為自己留個紀錄也希望能協助到有需要的開發人員。

安裝Bootstrap套件

在Web項目內使用Bootstrap套件,有一些前置作業要先完成。接下來的範例,從一個空的ASP.NET MVC項目開始建立,說明如何在這個項目內,完成使用Bootstrap套件的前置作業。

  1. 建立空白MVC項目。

  2. 使用NuGet安裝Bootstrap套件。

  3. 加入Home控制器以及其對應的Index檢視。

  4. Index檢視中加入Bootstrap套件的CSS參考、JavaScript參考,並且在html標籤加入「lang="en"」屬性。

    <html lang="en"><head>    <meta name="viewport" content="width=device-width" />    <title>Index</title>    <!-- Styles -->    <link href="/Content/bootstrap.css" rel="stylesheet">       </head><body>              <!-- Contents -->    <!-- Scripts -->    <script src="/Scripts/jquery-1.9.0.js"></script>    <script src="/Scripts/bootstrap.js"></script>       </body></html>
  5. 完成上述步驟也就完成使用Bootstrap套件的前置作業,後續就可以在body標籤的「Contents」批註之後,加入各種頁面內容。

套用Bootstrap樣式

在網站頁面上HTML卷標預設的顯示樣式,已經不能滿足使用者的審美眼光。將頁面上的HTML卷標套用Bootstrap樣式來呈現,能提供更美觀的使用者介面。

  1. 在Bootstrap官網上,找尋Bootstrap樣式的使用說明。

    • http://getbootstrap.com/

  2. 在Bootstrap樣式的使用說明中,找尋合適使用的樣式及說明。

  3. 依照樣式的說明,在body標籤的「Contents」批註之後加入對應的頁面內容。

    <!-- Contents --><table class="table table-striped">    <thead>        <tr>            <th>AAAAA</th>            <th>BBBBB</th>            <th>CCCCC</th>        </tr>    </thead>    <tbody>        <tr>            <td>A0001</td>            <td>B0001</td>            <td>C0001</td>        </tr>        <tr>            <td>A0002</td>            <td>B0002</td>            <td>C0002</td>        </tr>        <tr>            <td>A0003</td>            <td>B0003</td>            <td>C0003</td>        </tr>    </tbody></table>
  4. 接著執行Web項目,就可以在瀏覽器上看到套用Bootstrap樣式的顯示結果。

  5. 此時對比HTML卷標預設的顯示樣式,兩者只差異了「class="table table-striped"」屬性,但呈現效果卻有非常大的差異。

    <!-- Contents --><table>    <thead>        <tr>            <th>AAAAA</th>            <th>BBBBB</th>            <th>CCCCC</th>        </tr>    </thead>    <tbody>        <tr>            <td>A0001</td>            <td>B0001</td>            <td>C0001</td>        </tr>        <tr>            <td>A0002</td>            <td>B0002</td>            <td>C0002</td>        </tr>        <tr>            <td>A0003</td>            <td>B0003</td>            <td>C0003</td>        </tr>    </tbody></table>

套用Bootstrap組件

在Bootstrap套件中還加入了許多Bootstrap組件,這些組件組合既有的HTML卷標,提供各種更符合使用者輸入輸出習慣的畫面呈現。

  1. 在Bootstrap官網上,找尋Bootstrap組件的使用說明。

    • http://getbootstrap.com/

  2. 在Bootstrap組件的使用說明中,找尋合適使用的組件及說明。

  3. 依照組件的說明,在body標籤的「Contents」批註之後加入對應的頁面內容。

    <!-- Contents --><div class="progress">    <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width: 40%">        <span class="sr-only">40% Complete (success)</span>    </div></div><div class="progress">    <div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: 20%">        <span class="sr-only">20% Complete</span>    </div></div><div class="progress">    <div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 60%">        <span class="sr-only">60% Complete (warning)</span>    </div></div><div class="progress">    <div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="80" aria-valuemin="0" aria-valuemax="100" style="width: 80%">        <span class="sr-only">80% Complete (danger)</span>    </div></div>
  4. 接著執行Web項目,就可以在瀏覽器上看到Bootstrap組件的顯示結果。

參考資料
  • kkbruce - Bootstrap中文教學

  • Bootstrap - Bootstrap官網

[ASP.NET MVC] 使用Bootstrap套件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.