CSS-Battle

玩一下 css-battle

Battle #1

#1. Simply Square

在这里插入图片描述`

学习基本玩法,代码区外套body

<div></div>
<style>
  body{
    margin:0;
    background: #5d3a3a;
  }
  div {
    width: 200px;
    height: 200px;
    background: #b5e0ba;
  }
</style>
</style>

#2. Carrom

在这里插入图片描述

绝对定位

<div></div>
<div></div>
<div></div>
<div></div>
<style>
  body{
    padding:0;
    margin:0;
    background: #62374e;
  }
   div{
    width:50px;
    height:50px;
    background:#fdc57b;
    position:absolute;
  }
  div:nth-child(1){
    top:50px;
    left:50px
  }
  div:nth-child(2){
    top:50px;
    right:50px
  }
  div:nth-child(3){
    bottom:50px;
    left:50px
  }
  div:nth-child(4){
    bottom:50px;
    right:50px
  }
</style>

grid布局

<div></div>
<div></div>
<div></div>
<div></div> 
<style>
  body{
    margin:0;
    background:#62374e;
    display:grid;/* 网格布局 */
    grid-template-rows: 150px 150px;/* 设置每行高度 */
    grid-template-columns: 150px 150px;/* 设置每列宽度 */
    justify-items: center;/* 基于网格居中 */
    align-items: center;/* 基于网格居中 */
    column-gap:100px;/* 设置列间距 */
  }
  div {
    width: 50px;
    height: 50px;
    background: #fdc57b;
  }
</style>

#3. Push Button

在这里插入图片描述

<div class="box">
  <div class="out">
    <div class="mid">
      <div class="inner"></div>
    </div>
  </div>
</div>
<style>
  body{
    margin:0;
    background:#6592CF;
    display:flex;
    position:relative;
  }
  .box{
    margin:auto;
    width: 300px;
    height: 150px;
    background: #243D83;
  }
  /* 超出父元素,相对定位居中 */
  .out{
    position:relative;
    display:flex;
    left:50%;
    top:50%;
    transform: translate(-50%,-50%);
    background:#6592CF;
    width:250px;
    height:250px;
    border-radius:125px;;
  }
  .mid{
    margin:auto;
    background:#243D83;
    width:150px;
    height:150px;
    border-radius:75px;
    display:flex;
  }
  .inner{
    margin:auto;
    background:#EEB850;
    width:50px;
    height:50px;
    border-radius:25px;
  }
</style>

#4. Ups n Downs

在这里插入图片描述

定位

<div></div>
<div></div>
<div></div>
<style>
  body{
    background:#62306D
  }
  div {
    width: 100px;
    height: 100px;
    background: #F7EC7D;
    border-radius:50% 50% 0 0;
    position:absolute;
  }
  div:nth-child(odd){
    bottom:50px;
    transform:rotate(180deg)
  }
  div:nth-child(1){
    left:50px
  }
   div:nth-child(2){
     left:150px;
     bottom:150px;
   }
  div:nth-child(3){
    right:50px
  }
</style>

使用伪类

<div></div>
<style>
  body{
    margin:0;
    background:#62306D;
    position:relative;
  }
  div {
    position:absolute;
    left:50%;
    top:50%;
    transform: translate(-50%,-100%);
    width: 100px;
    height: 100px;
    border-radius: 50px 50px 0 0;
    background: #F7EC7D;
  }
  /* 默认为inline,必须设置content */
  div::before,div::after{
    position:absolute;
    content:"";
    display:block;
    width: 100px;
    height: 100px;
    border-radius:0 0 50px 50px;
    background: #F7EC7D;
    top:100%;
  }
  div::before{
    right:100%;
  }
  div::after{
    left:100%;
  }
</style>

#5. Acid Rain

在这里插入图片描述

<div class="box1"></div>
<div class="box2"></div>
<style>
  body{
    background:#0B2429;
  }
  .box1,.box2{
    background:#998235;
    position:absolute;
    left:50%;
    top:50%;
    transform: translate(-50%,-50%);
  }
  .box1,.box2,.box1::before{
    width: 120px;
    height: 120px;
    border-radius: 50% 0 50% 50%;
  }
  .box1::before{
    background:#F3AC3C;
    content:'';
    display: block;
    transform: translate(-50%,50%);
  }
  .box2{
     background:#F3AC3C;
     border-radius:50%;
     transform: translate(0,-100%);
     z-index:-1
  }
</style>

#6. Missing Slice

在这里插入图片描述

菜鸟尝试

<div id="outer">  
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
</div>
<style>
  body{
    background:#E3516E;
  }
  div{
    position:absolute;
    left: 50%;
    top:  50%;
    transform:translate(-50%,-50%);
  }
  #outer {
    width: 200px;
    height: 200px;
    border-radius:50%;
    overflow:hidden;
  }
  #outer div{
    width:100px;
    height:100px;
  }
  .box1{
    background:#51B5A9;
    transform:translate(-100%,-100%);
  }
  .box2{
    background:#FADE8B;
    transform:translate(0,-100%);
  }
  .box3{
    background:#F7F3D7;
    transform:translate(-100%,0);
  }
</style>

参考大佬

<div>
  <span></span>
  <span></span>
  <span></span>
</div>
<style>
  body{
    background:#E3516E;
  }
  div{
    position:absolute;
    left: 50%;
    top:  50%;
    transform:translate(-50%,-50%);
    width:200px;
    height:200px;
    display:flex;
    flex-wrap:wrap;
    border-radius:50%;
    overflow:hidden;
  }
  span{
    width:100px;
    height:100px;
  }
  span:nth-child(1){
    background:#51B5A9
  }
  span:nth-child(2){
    background:#FADE8B
  }
  span:nth-child(3){
    background:#F7F3D7
  }

</style>

#7. Leafy Trail

在这里插入图片描述

自己写的,有瑕疵,百分比不够精确

<div></div>
<div></div>
<div></div>
<style>
  body{
    background:#0B2429;
  }
  div {
    width: 150px;
    height: 150px;
    background: #998235;
    position:absolute;
    left:50%;
    top:50%;
    transform:translate(-50%,-50%);
    border-radius:66% 0 66% 0;
  }
  div:nth-child(1){
  background:#1A4341;
  transform:translate(-83%,-50%);
  }
  div:nth-child(3){
  background:#F3AC3C;
  transform:translate(-17%,-50%);
  }
</style>

参考大佬

<div></div>
<div></div>
<div></div>
<style>
  body{
    background:#0B2429;
  }
  div {
    width: 150px;
    height: 150px;
    background: #998235;
    position:absolute;
    left:50%;
    top:50%;
    transform:translate(-50%,-50%);
    border-radius:100px 0 100px 0;
  }
  div:nth-child(1){
  background:#1A4341;
  transform:translate(-125px,-50%);
  }
  div:nth-child(3){
  background:#F3AC3C;
  transform:translate(-25px,-50%);
  }
</style>

#8. Forking Crazy

在这里插入图片描述



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值