css常用屬性以及動畫效果程式碼
阿新 • • 發佈:2018-11-20
/*css常用效果,直接可以執行,基本包含了大部分樣式使用以及簡單動畫的實現*/
<!DOCTYPE html>
<html><head>
<meta charset="utf-8">
<title>css-test(runoob)</title>
<style>
#divBox{
position: relative;
}
div#div1,#div2,#div3
{
width:100px;
height:75px;
background-color:red;
padding: 20px;
background-clip: padding-box;
box-shadow:5px 5px 2px #888888 ;
}
div#div1{
/*改變位置*/
-webkit-transform:translate(100px,10px); /* Safari and Chrome */
/*改變與原來大小相比的比例*/
-webkit-transform: scale(0.9,0.8); /* Safari */
/*xy方向旋轉*/
/*-webkit-transform: skew(30deg,3deg);*/
/*-webkit-transform: skewX(10deg)/skewY();*/
matrix 方法有六個引數,包含旋轉,縮放,移動(平移)和傾斜功能。*/
-webkit-transform:matrix(0.866,0.5,-0.5,0.866,0,0);
/*transition: 2s;*/
-webkit-transition: width 0.1s, height 1.4s, -webkit-transform 2s; /* For Safari 3.1 to 6.0 */
/*transition: width 2s, height 0.1s, transform 4s;*/
/*-webkit-transition:2s;*/
}
transition-duration:1s;
transition-timing-function:linear;
transition-delay:2s;*/
/* Safari */
/*-webkit-transition-property:width;
-webkit-transition-duration:1s;
-webkit-transition-timing-function:linear;
-webkit-transition-delay:2s;*/
/*transition: width 1s linear 2s;*/
/* Safari */
/*-webkit-transition:width 1s linear 2s;*/
div#div1:hover{
width:200px;
height: 150px;
-webkit-transform: rotate(180deg); /* Chrome, Safari, Opera */
}
div#div2
{
display: inline-block;
transform:rotate(30deg);
-ms-transform:rotate(30deg); /* IE 9 */
-webkit-transform:rotate(30deg); /* Safari and Chrome */
box-shadow: 10px 10px 5px #888888;
background-clip: content-box;
text-shadow: 5px 5px 2px #888888 ;
/*content-box,padding-box,border-box*/
}
div#div3{
position: absolute;
right:0;
top: 0;
-webkit-transform:rotateX(60deg);
/*-webkit-transform:rotateY(160deg);*/
}
#tdiv1
{
display: inline-block;
float:right;
position: relative;
height: 200px;
width: 200px;
padding:10px;
border: 1px solid black;
perspective:150;
-webkit-perspective:220; /* Safari and Chrome */
perspective-origin: 10% 10%;
/*backface-visibility: visible|hidden;*/
}
#tdiv2
{
padding:50px;
position: absolute;
border: 1px solid black;
background-color: red;
transform: rotateY(60deg);
transform-style: preserve-3d;
-webkit-transform: rotateY(60deg); /* Safari and Chrome */
-webkit-transform-style: preserve-3d; /* Safari and Chrome */
/*transform-style: flat|preserve-3d;*/
}
#tdiv3
{
padding:40px;
position: absolute;
border: 1px solid black;
background-color: yellow;
transform: rotateY(-60deg);
-webkit-transform: rotateY(-60deg); /* Safari and Chrome */
}
#round,#stretch
{
border:15px solid transparent;
width:250px;
padding:10px 20px;
}
#round
{
-webkit-border-image:url(images/border.png) 30 30 round; /* Safari 5 and older */
-o-border-image:url(images/border.png) 30 30 round; /* Opera */
border-image:url(images/border.png) 30 30 round;
resize:both;
overflow:auto;
}
#stretch
{
*-webkit-border-image:url(images/border.png) 30 30 stretch; /* Safari 5 and older */*/
-o-border-image:url(images/border.png) 30 30 stretch; /* Opera */
border-image:url(images/border.png) 30 30 stretch;
}
#filterImg{
-webkit-filter: grayscale(50%);
/*filter: none | blur() | brightness() | contrast() | drop-shadow() | grayscale()
| hue-rotate() | invert() | opacity() | saturate() | sepia() | url();*/
}
/*border-top-right-radius
border-radius: 50px/15px;
border-radius: 15px/50px;
*/
.circle {
border-radius:50%;
background: red;
padding: 20px;
width: 100px;
height: 75px;
display: inline-block;
}
#rcorners9
{
/*animation:myfirst 5s;*/
-webkit-animation:myfirst 5s; /* Safari and Chrome */
}
/*@keyframes myfirst
{
from {background:red;}
to {background:yellow;}
}*/
@-webkit-keyframes myfirst /* Safari and Chrome */
{
from {background:red;}
to {background:yellow;}
}
#rcorners10
{
opacity: 0.7;
/*animation:myfirst 5s;*/
-webkit-animation:myfirst2 5s; /* Safari and Chrome */
}
@-webkit-keyframes myfirst2 /* Safari and Chrome */
{
0% {background:red;}
25% {background:yellow;}
50% {background:blue;}
100% {background:green;}
}
/*#rcorners12*/
{
position: relative;
width:30px;
height:30px;
background:red;
/*animation:myfirst 5s;*/
-webkit-animation:myfirst3 5s; /*Safari and Chrome */
-webkit-animation-iteration-count: infinite;
-webkit-animation-direction: alternate;
/*-webkit-animation: myfirst3 5s linear 2s infinite alternate;*/
}
@-webkit-keyframes myfirst3{
0% {background:red; left:0px; top:0px;}
25% {background:yellow; left:100px; top:0px;}
50% {background:blue; left:100px; top:100px;}
75% {background:green; left:0px; top:100px;}
100% {background:red; left:0px; top:0px;}
}
/*#example1 {
background-image: url(images/pen.png), url(images/paper.png);
background-position: right bottom, left top ;
background-repeat: no-repeat, repeat ;
padding: 15px;
}*/
#round,#stretch
{
background-image:url('images/jy_suess.png');
background-repeat:no-repeat;
background-position:left;
}
#example1 {
background: url(images/flower.png) right bottom no-repeat, url(images/paper.png) left top repeat;
padding: 15px;
box-shadow:0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);/*卡片效果*/
word-wrap:break-word;
/*word-break:keep-all;*/
/*word-break:break-all;*/
}
h2
{
/*-webkit-column-span:all; /* Safari and Chrome */
}
#column{
-webkit-column-count:2;
-webkit-column-gap:10px;
/*-webkit-column-rule-style:solid;
-webkit-column-rule-color: lightblue; */
-webkit-column-rule: 3px dotted lightblue;
}
#round
{
background-origin:border-box;
}
#stretch
{
background-origin:content-box;
}
/*content-box,padding-box,border-box*/
#grad1 {
height: 20px;
background: -webkit-linear-gradient(left,yellow, red); /* Safari 5.1 - 6.0 */
/*background: -webkit-linear-gradient(yellow, red); /* Safari 5.1 - 6.0 */*/
/*background: -o-linear-gradient(red, blue); /* Opera 11.1 - 12.0 */*/
/*background: -moz-linear-gradient(red, blue); /* Firefox 3.6 - 15 */*/
/*background: linear-gradient(red, blue); /* 標準的語法(必須放在最後) */*/
}
#grad2{
height: 80px;
width: 20px;
margin-top: 10px;
background: linear-gradient(yellow,red) ;
display: inline-block;
}
#grad3{
height: 80px;
width: 150px;
margin-top: 10px;
display: inline-block;
background: linear-gradient(to bottom right, yellow , red); /* 標準的語法(必須放在最後)*/
}
#grad4{
height: 80px;
width: 70px;
margin-top: 10px;
display: inline-block;
background: linear-gradient(45deg, yellow , red);
}
#grad5{
height: 80px;
width: 70px;
margin-top: 10px;
display: inline-block;
background: linear-gradient(green,yellow , red);
}
#grad6{
height: 80px;
width: 70px;
margin-top: 10px;
display: inline-block;
background: linear-gradient(green 10%,yellow 20%, red 70%);
}
#grad7{
height: 30px;
margin-top: 5px;
background: repeating-linear-gradient(to right,rgba(255,0,0,0),rgba(255,0,0,1));
}
#grad8{
height: 30px;
margin-top: 5px;
background: repeating-linear-gradient(to right,red, yellow 10%, green 20%); /* 標準的語法(必須放在最後) */
}
#grad9 {
display: inline-block;
height: 80px;
width: 100px;
background: radial-gradient(circle,red, orange, yellow);
/*background: radial-gradient(60% 55%, closest-side,blue,green,yellow,black);*/
/*closest-side
farthest-side
closest-corner
farthest-corner*/
/*repeating-radial-gradient*/
}
/*text-overflow:ellipsis/hidden/clip*/
div.container
{
width:30em;
border:1em solid;
}
div.box
{
box-sizing:border-box;
width:50%;
border:1em solid red;
float:left;
}
#grad10 {
display: inline-block;
margin-left: 5px;
height: 40px;
width: 50px;
outline:2px solid red;
outline-offset:5px;
-webkit-appearance:button;
/*appearance: normal|icon|window|button|menu|field;*/
}
</style>
</head><body>
<div id="div1">你好。這是一個 DIV 元素。</div>
<div id="div2">你好。這是一個 DIV 元素。</div>
<div id="div3">你好。這是一個 DIV3D 元素。</div>
<div id="tdiv1">
<div id="tdiv2">HELLO
<div id="tdiv3">YELLOW</div>
</div>
</div>
<p><b>注意: </b> Internet Explorer 不支援 border-image 屬性。</p>
<p> border-image 屬性用於設定圖片的邊框。</p>
<div id="round">這裡,影象平鋪(重複)來填充該區域。</div>
<br>
<div id="stretch">這裡,影象被拉伸以填充該區域。</div>
<p>這是我們使用的圖片素材:</p>
<img id="filterImg" src="images/border.png" />
<p>橢圓邊框 - border-radius: 50% && animiation:</p>
<p class="circle" id="rcorners9"></p>
<p class="circle" id="rcorners10"></p>
<div id="rcorners12"></div>
<div id="example1">
<h1>Lorem Ipsum Dolor</h1>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p id="column">
Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
</p>
</div>
<h3>線性漸變 - 從上到下</h3>
<p>從頂部開始的線性漸變。起點是紅色,慢慢過渡到藍色:</p>
<div id="grad1"></div>
<div id="grad2"></div>
<div id="grad3"></div>
<div id="grad4"></div>
<div id="grad5"></div>
<div id="grad6"></div>
<div id="grad7"></div>
<div id="grad8"></div>
<div id="grad9"></div>
<div id="grad10"></div>
<p><strong>注意:</strong> Internet Explorer 9 及之前的版本不支援漸變。</p>
<div class="container">
<div class="box">這個 div 佔據了左邊的一半。.</div>
<div class="box">這個 div 佔據了右邊的一半。</div>
</div>
</body>
</html>