HTML+CSS大风车及十字架的实现

19 篇文章 0 订阅
9 篇文章 1 订阅

说起大风车勾起了多少人的回忆,

我们今天就利用CSS做一个大风车并且让它转起来。

首先还是老规矩——先上效果图:


一................ 不是说好了转起来的吗?怎么在那不动啊。哈哈哈。。。。偷笑


老毛病又犯了是不,不要着急嘛。

由于不会搞视频,只能等你们自己做出来,你们再去看效果吧,真的很炫酷的哦!

HTML代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>第一种</title>
    <link rel="stylesheet" type="text/css" href="cross.css">
</head>

<body>
    <div id="overall">
        <div id="first"></div>
        <div id="second"></div>
        <div id="third">
            <img src="3D.ico">
        </div>
        <div id="fourth"></div>
        <div id="fifth"></div>
    </div>
</body>

</html>

代码很少同样也很简单,就是五个div进行的定位组成的大风车

来看看是怎么定位的吧:

div {
    width: 100px;
    height: 100px;
    /*float: left;*/
    position: absolute;
    border-color: orange;
    border-radius: 20px;
    /*border-spacing: 5px;*/
}

#overall {
    width: 300px;
    height: 300px;
    position: absolute;
    left: 50%;
    top: 50%;
    margin-top: -150px;
    margin-left: -150px;
    border: none;
    animation:myanim 3s infinite;
    -webkit-animation: myanim 3s infinite;
}

#first {
    background-color: #63A12C;
    left: 100px;
}

#second {
    background-color: #2C34A1;
    top: 100px;
}

#third {
    background-color: #3D82B7;
    top: 100px;
    left: 100px;
}

img {
    width: 24px;
    height: 24px;
    position: absolute;
    left: 50%;
    top: 50%;
    margin-top: -12px;
    margin-left: -12px;
}

#fourth {
    background-color: #A92D7F;
    top: 100px;
    left: 200px;
}

#fifth {
    background-color: #2ACBB6;
    top: 200px;
    left: 100px;
}
/* 旋转效果*/
@keyframes myanim {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(-360deg);
    }
}

@-webkit-keyframes myanim {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(-360deg);
    }
}

同学会问怎么让它动起来的呢?

嘿嘿嘿害羞,就在上面那段你看不懂的代码,

搞回去细细琢磨一下吧。


第二种样式只有CSS和上面略微不同:

div {
    width: 100px;
    height: 100px;
    /*border-radius: 50%;*/
}

.overall {
    width: 300px;
    height: 300px;
    position: fixed;
    left: 50%;
    top: 50%;
    -webkit-transform: translate(-50%, -50%);
    display: block;
    /*    -webkit-transition:0.4s linear;
    -webkit-transition:0.4s ease-in;*/
    -webkit-transition: all 1s ease-in-out;
}

#first {
    background-color: #63A12C;
    margin-left: 100px;
}

#second {
    background-color: #2C34A1;
    margin-right: 200px;
}

#third {
    background-color: #3D82B7;
    margin-left: 100px;
    margin-top: -100px;
}

img {
    width: 24px;
    height: 24px;
    /*µÚÒ»ÖÖ·½·¨*/
    /*    position: absolute;
    left: 50%;
    top: 50%;
    margin-top: -12px;
    margin-left: -12px;*/
    margin-top: 38px;
    margin-left: 38px;
}

#fourth {
    background-color: #A92D7F;
    margin-left: 200px;
    margin-top: -100px;
}

#fifth {
    background-color: #2ACBB6;
    margin-left: 100px;
}

.overall:hover {
    -webkit-transform: rotate(180deg) scale(3.0) translate(100px, 0);
}

第三种:

div {
    width: 100px;
    height: 100px;
    border-radius: 50%;
}

.overall {
    width: 300px;
    height: 300px;
    position: fixed;
    left: 50%;
    top: 50%;
    -webkit-transform: translate(-50%, -50%);
}

#first {
    background-color: #3D82B7;
    margin-left: 100px;
}

#second {
    background-color: #2C34A1;
    margin-right: 200px;
}

#third {
    background-color: #9400D3;
    margin-left: 100px;
    margin-top: -100px;
    display: table;
    text-align: center;
    -webkit-transition: background-color 1s ease-in;
}

#third:hover {
    background-color: #32CD32;
}

.img {
    display: table-cell;
    vertical-align: middle;
}

#fourth {
    background-color: #A92D7F;
    margin-left: 200px;
    margin-top: -100px;
}

#fifth {
    background-color: #2ACBB6;
    margin-left: 100px;
}

好了这三种方法回去试一下吧,

有助于帮助你学习CSS中的定位

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值