css常见问题前端面试必问(持续更新)

CSS

清除浮动

1、浮动元素后面加个div,style{clear:both}
2、浮动元素加上overflow:hidden或者overflow:auto
3、利用:after伪元素,:after伪元素实现元素末尾添加一个看不见的块元素(Block element)清理浮动。

浮动元素类名::after{
}

两栏登高布局

.container {
   overflow: hidden;
}
.left,
.right {
   padding-bottom: 9999px;
   margin-bottom: -9999px;
   width: 300px;
   float: left;
   background-color: rgb(124, 124, 124);
}

<div class="container">
    <div class="left">left</div>
    <div class="right">rigth</div>
</div>

三列布局

    * {
      margin: 0;
      padding: 0;
    }

    /* float+margin */
    /* .left {
      width: 100px;
      height: 300px;
      background-color: green;
      float: left;

    }

    .right {
      width: 100px;
      height: 300px;
      background-color: red;
      float: right;

    }

    .content {
      height: 300px;
      background-color: blue;
      margin-right: 100px;
      margin-left: 100px;
    } */

    /* float+overflow */
    /* .left {
      width: 100px;
      height: 300px;
      background-color: green;
      float: left;
    }

    .right {
      width: 100px;
      height: 300px;
      background-color: red;
      overflow: hidden;
      float: right;
    }

    .content {
      height: 300px;
      background-color: blue;

    } */

    /* flex */
    .main {
      display: flex;
    }

    .left {
      width: 100px;
      height: 300px;
      background-color: green;
    }

    .right {
      width: 100px;
      height: 300px;
      background-color: red;
    }

    .content {
      height: 300px;
      background-color: blue;
      flex: 1;

    }


  <div class="main">
    <div class="left">left</div>
    <div class="right">right</div>
    <div class="content">content</div>
  </div>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值