传统的网站制作或者web应用中,如果我们需要创建一个提示的话,通常使用图片来生成小三角,今天这里我们分享一个动画小教程,帮助你快速学习如何使用纯CSS来生成一个三角形。
<style type="text/css">
@import url(http://fonts.googleapis.com/css?family=Andika);
.triangle-demo {
width: 100px;
height: 100px;
margin: 0 auto;
background: tan;
border-top: 0 solid #EE7C31;
border-left: 0 solid #F5D97B;
border-bottom: 0 solid #D94948;
border-right: 0 solid #8DB434;
transition: 0.8s 0.2s;
}
.step-1 .triangle-demo {
border-top-width: 10px;
}
.step-2 .triangle-demo {
border-left-width: 10px;
}
.step-3 .triangle-demo {
border-right-width: 10px;
}
.step-4 .triangle-demo {
border-bottom-width: 10px;
}
.step-6 .triangle-demo {
background: transparent;
}
.step-7 .triangle-demo {
width: 0;
height: 0;
}
.step-8 .triangle-demo {
border-left-color: transparent;
}
.step-9 .triangle-demo {
border-right-color: transparent;
}
.step-10 .triangle-demo {
border-top-color: transparent;
}
.triangle-title {
width: 300px;
padding: 1rem;
color: white;
background: #D94948;
border-radius: 20px;
margin: auto;
opacity: 0;
transition: 0.8s 0.2s;
}
.step-11 .triangle-title {
opacity: 1;
}
body {
background: #333;
font-family: 'Andika', sans-serif;
color: white;
text-align: center;
font-size: large;
transform: translateZ(0);
}
.steps {
position: relative;
height: 45px;
margin-bottom:20px;
}
.steps > div {
position: absolute;
top: 0;
left: 0;
width: 100%;
opacity: 0;
background: #333;
transition: 0.3s;
}
.steps .step-0 {
opacity: 1;
}
.step-1 .steps .step-1 {
opacity: 1;
}
.step-2 .steps .step-2 {
opacity: 1;
}
.step-5 .steps .step-5 {
opacity: 1;
}
.step-6 .steps .step-6 {
opacity: 1;
}
.step-7 .steps .step-7 {
opacity: 1;
}
.step-8 .steps .step-8 {
opacity: 1;
}
.step-11 .steps .step-11 {
opacity: 1;
}
h1 {
text-transform: uppercase;
letter-spacing: 1px;
font-size: 14px;
border-bottom: 1px solid #555;
color: #999;
padding-bottom:10px;
font-family: Arial;
font-weight: normal;
}
</style>