Bootstrap是一種流行的CSS框架,可以幫助開發人員快速、簡單地創建具有響應式設計和漂亮外觀的網站。Bootstrap還提供了各種組件和工具,包括按鈕、表格、表單和導航欄等,可以用于HTML代碼中。以下是一些使用Bootstrap的示例代碼:
<!-- 引入Bootstrap CSS文件 --> <link rel="stylesheet" > <!-- 創建一個導航欄 --> <nav class="navbar navbar-expand-lg navbar-light bg-light"> <div class="container"> <a class="navbar-brand" href="#">Logo</a> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav me-auto"> <li class="nav-item"> <a class="nav-link active" aria-current="page" href="#">Home</a> </li> <li class="nav-item"> <a class="nav-link" href="#">About</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Contact</a> </li> </ul> </div> </div> </nav> <!-- 創建一個表單 --> <form> <div class="mb-3"> <label for="exampleInputEmail1" class="form-label">Email address</label> <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp"> <div id="emailHelp" class="form-text">We'll never share your email with anyone else.</div> </div> <div class="mb-3"> <label for="exampleInputPassword1" class="form-label">Password</label> <input type="password" class="form-control" id="exampleInputPassword1"> </div> <div class="mb-3 form-check"> <input type="checkbox" class="form-check-input" id="exampleCheck1"> <label class="form-check-label" for="exampleCheck1">Check me out</label> </div> <button type="submit" class="btn btn-primary">Submit</button> </form>上述代碼中,第一個pre標簽包含了引入Bootstrap CSS文件的代碼,以及創建一個導航欄的代碼。第二個pre標簽包含了創建一個表單的代碼??梢钥吹?,使用Bootstrap可以大大簡化HTML代碼的編寫和樣式的設計,使網站開發更加高效和美觀。