線上書籍

Home

111網頁前端設計工程師培訓班

同一個欄可以有多個斷點樣式,讓網頁在不同螢幕尺寸呈現不同佈局

ex:當瀏覽器超過992px會採用 .col-lg-4樣式,當瀏覽器小於576px會採用 .col-sm-8樣式
multi_breakpoint.htm

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>col-{breakpoint}-auto</title> <!-- Bootstrap CSS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous"> </head> <Style> html, body {height: 100%;} .container{border:0px solid;background-color:#e5e5e5;} .col{background-color:#ff0000;height:50px;margin-top:10px} .col-lg-4{background-color:#ff9900;height:50px;margin-top:10px} .col-lg-8{background-color:#ffffcc;height:50px;margin-top:10px} .col-sm-8{background-color:#ff9900;height:50px;margin-top:10px} .col-sm-4{background-color:#ffcc00;height:50px;margin-top:10px} </style> <body> <div class="container"> <div class="row"> <div class="col-lg-4 col-sm-8">.col-lg-4 .col-sm-8</div> <div class="col-lg-8 col-sm-4">.col-lg-8 .col-sm-4</div> </div> </div> <!-- Bootstrap JS --> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"></script> <script> let box = document.querySelector('.container'); box.insertAdjacentHTML("afterend", "<div style='text-align:center'>container寬度:"+box.clientWidth+"px</div>"); </script> </body> </html>