zoukankan      html  css  js  c++  java
  • 【前端知识体系-CSS相关】Bootstrap相关知识

    1.Bootstrap 的优缺点?

    • 优点:CSS代码结构合理,现成的代码可以直接使用(响应式布局)
    • 缺点:定制流程较为繁琐,体积大

    2.如何实现响应式布局?

    • 原理:通过media query设置不同分辨率的class
    • 使用:为不同分辨率选择不同的class

    3.如何定制自己的bootstrap样式?

    1. 使用CSS同名类覆盖(门槛低,见效快,可能会有bug)
    2. 修改源码重新构建(一次性彻底解决)
      [
      bootstrap.scss是入口文件,修改这个文件内容之后,使用node-sass重新编译scss文件
      node-sass --output-style expanded bootstrap/custom/scss/bootstrap.scss > bootstrap/custom/dist/css/bootstrap.css
      ]
    3. 引用Scss源文件,修改变量(类似于预处理器的使用方式, 徐亚什么模块引入什么模块,会更加灵活,推荐)
      [
      1. 创建一个自己的custom.scss文件
      $primary: greed; @import './botstrap-custom/scss/bootstrap.scss'
      ]

    4.如何实现一个响应式布局框架?

    [!NOTE]
    面试常考考点,要求模拟实现boostrap的底层实现原理。

    上面的[!NOTE]是行匹配模式,默认情况下支持类型NOTE,TIP,WARNING和DANGER。

    4.1 JS的模拟实现

    <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>
    

    4.2 CSS的模拟实现

    <style>
            .container{
                height: 40px;
                margin: 0 auto;
                background-color: rebeccapurple;
            }
    
            /*媒体查询*/
            @media screen  and (max- 768px){
                .container{
                     100%;
                }
            }
         
            @media screen  and (min- 768px) and (max- 992px){
                .container{
                     750px;
                }
            }
            @media screen  and (min- 992px) and (max- 1200px){
                .container{
                     970px;
                }
            }
            @media screen  and (min- 1200px){
                .container{
                     1170px;
                }
            }
    </style>
    <div class="container"></div>
    

    [!NOTE]
    关键点:mediaQuery, 浮动,响应式布局,resize事件

  • 相关阅读:
    Win10 UWP Tile Generator
    Win10 BackgroundTask
    UWP Tiles
    UWP Ad
    Win10 build package error collections
    Win10 八步打通 Nuget 发布打包
    Win10 UI入门 pivot multiable DataTemplate
    Win10 UI入门 导航滑动条 求UWP工作
    UWP Control Toolkit Collections 求UWP工作
    Win10 UI入门 SliderRectangle
  • 原文地址:https://www.cnblogs.com/fecommunity/p/11893537.html
Copyright © 2011-2022 走看看