Css3、Scss 常用的布局设置-通用

常见的几种css 布局

  • 垂直居中
// 第一种 绝对定位
#parent{
  position:relative;
  height:400px;
  .son{
   position:absolute;
   width:100px;
   height:100px;
   top: 50%;
   transform: translateY(-50%); 
  }
}
// 第二种 flex布局
#parent{
   display:flex;
   align-items:center;
   height:400px;
  .son{
    width:100px;
    height:100px;
  }
}
// 第三种  margin
#parent{
  position:relative;
  height: 400px;
  .son{
   position:absolute;
   width:100px;
   height:100px;
   top:0;
   bottom:0;
   margin:auto; 
  }
}
复制代码
  • 水平居中
// 多个块级元素
#parent{
  height:100px;
  text-align:center;
  .son{
    width:100px;
    height:100px;
    display:inline-block;
  }
}
// 绝对定位
#parent{
  position:relative;
  height:100px;
  .son{
    position:absolute;
    width:100px;
    height:100px;
    left:50%;
    transform:translateX(-50%)
  }
}
// 块级元素
#parent{
  height:100px;
  .son{
    width:100px;
    height:100px;
    margin:0 auto;
  }
}
// 行内元素
#parent{
  height:100px;
  .son{
    width:100px;
    height:100px;
    display:inline-block;
    text-align:center;
  }
}
// flex布局
#parent{
  display:flex;
  justify-content:center;
  height:100px;
  .son{
    width:100px;
    height:100px;
  }
}
复制代码
  • 左定宽右自适应
// flex 布局
 #Box{
  width: 100%;
  height:400px;
  .left{
    float:left;
    width:100px;
    height:400px;
  }
  .right{
    flex:1;
    height:400px;
  }
}
// float + margin 
 .left {
      float: left;
      width: 100px;
      height: 100%;
      background-color: antiquewhite;
   }
 .right {
      margin-left: 100px;
      height: 100%;
      background-color: rgb(77, 87, 184);
   }
// float + overflow
 .left {
      float: left;
      width: 100px;
      height: 400px;
      background-color: antiquewhite;
   }
   .right {
      height: 400px;
      overflow: hidden;
      background-color: rgb(77, 87, 184);
    }
复制代码

请用CSS3写一个旋转的硬币

.coin{
  width:100px;
  height:100px;
  transform-style:preserve-3d;
  transform: rotate3d(-1, -1, 0, 45deg);
  animation: coin 15s linear;
}
.coin>div{
  position:absolute;
  width:100px;
  height:100px;
}
.front{
  width:100px;
  height:100px;
  border-radius:50%;
  transform: translateZ(2px); // 硬币厚度
}
.back{
  width:100px;
  height:100px;
  border-radius:50%;
}
@keyframes coin{
  from{
    transform: rotateY(0deg);
  }
  to{
    transform: rotateY(360deg);
  }
}
复制代码

内容仅供参考使用!

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值