☆第2弹☆【WEB前端工程师-基础面试题】--CSS/JavaScript

1、盒子在父元素中垂直居中的3中方式

  • 方法1:已知宽高,水平、垂直各移动自身宽、高度的一半
    •   <style>
          .box{
            width: 500px;
            height: 400px;
            border: 3px dashed red;
            margin: 100px auto;
            position: relative;
          }
      
          .son{
            width: 150px;
            height: 150px;
            background-color:tomato;
            position: absolute;
            left:50%;
            top:50%;
            /* 方法1 :已知宽高,水平、垂直各移动自身宽、高度的一半*/
            argin-left: -75px;
            margin-top:-75px; 
      
          }
        </style>
      </head>
      <body>
        <div class="box">
          <div class="son"></div>
        </div>
      </body>
  • 方法2:未知宽高,移动自身高度、宽度一半
    •   <style>
          .box{
            width: 500px;
            height: 400px;
            border: 3px dashed red;
            margin: 100px auto;
            position: relative;
          }
      
          .son{
            width: 150px;
            height: 150px;
            background-color:tomato;
            position: absolute;
            left:50%;
            top:50%;
            /* 方法2:假设未知宽高,移动自身高度、宽度一半*/
            transform: translate(-50%,-50%); 
          }
        </style>
      </head>
      <body>
        <div class="box">
          <div class="son"></div>
        </div>
      </body>
  • 方法3:弹性布局flex,写给父元素
    • <style>
          .box{
            width: 500px;
            height: 400px;
            border: 3px dashed red;
            margin: 100px auto;
            position: relative;
            /****方法3:弹性布局flex,写给父元素****/
            display:flex;
            align-items:center;
            justify-content: center;
          }
      
          .son{
            width: 150px;
            height: 150px;
            background-color:tomato;
            position: absolute;
          }
        </style>
      </head>
      <body>
        <div class="box">
          <div class="son"></div>
        </div>
      </body>

2、清除浮动方法4种

        ①给父元素设置高度

        ②BFC保护(块级格式化上下文):给父元素设置overflow:hidden;

        ③在父元素末尾添加一个虚拟子元素,转为块元素,设置clear:both;

        ④伪元素

<style>
    .box{
      /*方法1:给父元素设置高度 */
      /*height:200px;*/
      width: 700px;
      background-color:grey;
      /*方法2:块级格式化上下文BFC */
      /* overflow: hidden; */
    }

    .box>div{
      width:200px;
      height: 200px;
      float: left;
    }

    .one{
      background-color: orangered;
    }
    
    .two{
      background-color:aquamarine
    }

    .three{
      background-color:greenyellow;
    }

    /* 方法3: */
    .clear{
      clear:both;
      /* 必须是块状标签 */
      display: block;
    }

    /* 方法4:添加伪元素 */
    /* .box::after{
      content:"";
      display:flex;
      clear:both;
    } */
  </style>
</head>
<body>

   <div class="box">
    <div class="one"></div>
    <div class="two"></div>
    <div class="three"></div>
    <!-- 方法3:给父元素最后面添加一个假的子元素 -->
    <!-- <span class="clear"></span> -->
   </div>

3、渐进增强和优雅降级

①渐进增强 progressive enhancement

        先保证基本的功能,再改进和追加功能。

        针对低版本浏览器进行构建页面,保证基本的功能,然后 再针对高级浏览器进行效果、交互等改进和追加功能达到更好的用户体验。

②优雅降级 graceful degradation:

        构建完整的功能,再针对低版本浏览器进行兼容  -webkit-    -ms-   -o-  ...

4、盒子模型

1、边框border

边框样式属性

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

长安梦我

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值