$primary: greed; @import './botstrap-custom/scss/bootstrap.scss'
[!NOTE]
面試常考考點,要求模擬實現boostrap的底層實現原理。css
上面的[!NOTE]是行匹配模式,默認狀況下支持類型NOTE,TIP,WARNING和DANGER。html
<style> .container{ height: 40px; margin: 0 auto; background-color: rebeccapurple; } </style> <div class="container"></div> <script> window.addEventListener("load", function () { // 1. 獲取容器 let container = document.querySelector(".container"); let clientW = 0; resize(); // 2. 監聽窗口的大小變化 window.addEventListener("resize", resize); function resize() { // 2.1 獲取改變後的寬度 clientW = window.innerWidth; // 2.2 判斷 if(clientW >= 1200){ // 超大屏幕 container.style.width = "1170px"; }else if(clientW >= 992){ // 大屏幕 container.style.width = "970px"; }else if(clientW >= 768){ // 小屏幕 container.style.width = "750px"; }else { // 超小屏幕 container.style.width = "100%"; } } }); </script>
<style> .container{ height: 40px; margin: 0 auto; background-color: rebeccapurple; } /*媒體查詢*/ @media screen and (max-width: 768px){ .container{ width: 100%; } } @media screen and (min-width: 768px) and (max-width: 992px){ .container{ width: 750px; } } @media screen and (min-width: 992px) and (max-width: 1200px){ .container{ width: 970px; } } @media screen and (min-width: 1200px){ .container{ width: 1170px; } } </style> <div class="container"></div>
[!NOTE]
關鍵點:mediaQuery, 浮動,響應式佈局,resize事件node