css3 變換、過渡效果、動畫

1 CSS3 選擇器

1.1 基本選擇器

1.2 層級

  • 空格

  • >

  • + .item+li

  • ~ .item~p

1.3 屬性選擇器

  • [attr]

  • [attr=value]

  • [attr^=value]

  • [attr$=value]

  • [attr*=value]

  • [][][]

1.4 偽類選擇器

  • :link

  • :visited

  • :hover

  • :active

  • :focus

  • :first-child .list li:first-child

  • :last-child

  • :nth-child() 從1開始 odd even

  • :nth-last-child() 從1開始

  • :only-child li:only-child

  • :first-of-type

  • :last-of-type

  • nth-of-type()

  • nth-last-of-type()

  • only-of-type

<ul>
<li></li>
<li></li>
<p></p>
<li>li:nth-of-type(3) </li>
<li></li>
<li></li>
</ul>
?
li:nth-of-type(3) ? #選擇到
li:nth-child(3) ? #沒有滿足條件的元素

1.5 偽元素選擇器

  • ::before .item::before

  • ::after .clearfix::after {content:''; display:block; clear:both}

<div class="nav clearfix"> 
子元素浮動
[::after 此處是偽元素創建的]
</div>
?
?
<div class="banner">
</div>
  • ::first-letter

  • ::first-line

  • ::selection

  • ::placeholder ::placeholder {color:red} <input placeholder="請輸入用戶名">

?

2 CSS3 基礎

2.1 新增顏色單位

  • rgba() 不透明0~1

2.2 新增長度單位

  • rem

  • vw

  • vh

?

3 新增的CSS3屬性

3.1 邊框圓角

border-radius 長度單位
border-top-left-radius
border-top-righ-radius
border-bottom-left-radius
border-bottom-right-radius

3.2 布局

display: 值很多很多 .... table table-row...
box-sizing: content-box(默認值) / border-box

3.3 外輪廓

outline:1px solid #ccc
outline-style
outline-color
outline-width

3.4 不透明度

opacity: 0~1

?

3.5 陰影

box-shadow:水平偏移 垂直偏移; ? 偏移可以負值
box-shadow:水平偏移 垂直偏移 顏色;
box-shadow:水平偏移 垂直偏移 模糊值 顏色; /*最常見的*/
box-shadow:水平偏移 垂直偏移 模糊值 外延值 顏色;
 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>盒子陰影</title>
 6     <style>
 7         .item {
 8             display: inline-block;
 9             margin:20px;
10             width: 100px;
11             height: 100px;
12             border: 1px solid #999;
13         }
14 
15         .item01 {
16             box-shadow: 10px 10px;
17         }
18         .item02 {
19             box-shadow: 3px 3px #ccc;
20         }
21         .item03 {
22             /*大部分 需要設置這幾個值*/
23             box-shadow: 10px 10px 10px #ccc;
24         }
25         .item04 {
26             /*外延值*/
27             box-shadow: 0px 0px 0px 120px #ccc;
28         }
29 
30         .item05 {
31             /*多重陰影*/
32             box-shadow: 0px 0px 3px 5px red,
33                         0px 0px 3px 10px orange,
34                         0px 0px 3px 15px yellow,
35                         0px 0px 3px 20px green,
36                         0px 0px 3px 25px cyan,
37                         0px 0px 3px 30px blue,
38                         0px 0px 3px 35px purple;
39         }
40     </style>
41 </head>
42 <body>
43     <h1>陰影</h1>
44     <hr>
45 
46 
47     <div class="item item01">01</div>
48     <div class="item item02">02</div>
49     <div class="item item03">03</div>
50     <div class="item item04">04</div>
51     <div class="item item05">05</div>
52     <div class="item item06">06</div>
53 
54     <hr>
55 
56     
57 </body>
58 </html>
陰影
?

3.5 背景

background-size: cover / contain / 400px 300px / 100% 100%
background: color image postion/size repeat attachment

?

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>背景</title>
 6     <style>
 7         .item {
 8             /*display: block;*/
 9             width: 300px;
10             height: 300px;
11             border: 1px solid #ccc;
12             background: url("./images/meinv02.jpg") no-repeat;
13             
14             /*設置背景圖片的尺寸*/
15             /*background-size: cover; 優先 鋪滿元素。 多余的圖片裁掉 保證原圖比例*/
16             /*background-size: contain; 優先 保證圖片顯示完整,可能元素不能鋪滿。 保證原圖比例*/
17 
18             /*background-size:100px 200px;指定背景大小*/
19             /*background-size:100% 100%;*/
20 
21 
22             /*background: url('./images/meinv02.jpg') 10px 20px/cover;*/
23         }
24     </style>
25 </head>
26 <body>
27     <div class="item">
28         
29     </div>
30 </body>
31 </html>
背景

?

3.6 CSS3變換

  • transform

    translatex() 
    translatey()
    translate(x, y)
    rotate() 角度 deg
    skewx() 角度deg
    skewy()
    skew(x, y)
  • transform-origin 變換的原點。 對translate沒有意義。 對rotate影響大

?

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>變換</title>
 6     <style>
 7         .box {
 8             display: inline-block;
 9             margin: 30px;
10             width: 100px;
11             height: 100px;
12             border:2px dashed orange;
13 
14             vertical-align: middle;
15         }
16         .item {
17             border: 1px solid #999;
18             background: #ccc;
19             height:99px;
20         }
21 
22         .item01 {
23             /*位移 移動*/
24             transform: translate(20px, 20px);
25             /*transform: translatex(10px) translatey(10px);*/
26             /*transform: translatey(10px);*/
27         }
28 
29         .item02 {
30             /*旋轉 deg角度  0~360deg*/
31             transform: rotate(60deg)
32         }
33 
34         .item03 {
35             /*扭曲*/
36             transform: skewx(60deg) skewy(60deg);
37         }
38 
39         .content {
40             margin: 30px;
41             width: 100px;
42             height: 100px;
43             border: 1px solid #999;
44             transform: rotate(60deg);
45             transform-origin: left top;/*transform-origin 變換的原點*/
46         }
47     </style>
48 </head>
49 <body>
50     
51     <div class="box">
52         <div class="item item01"></div>
53     </div>
54 
55         <div class="box">
56         <div class="item item02">HELLO</div>
57     </div>
58     
59         <div class="box">
60         <div class="item item03">HELLO</div>
61     </div>
62     
63     <hr>
64 
65 
66     <div class="content">
67         HELLO
68     </div>
69 
70 </body>
71 </html>
變換

?

3.7 過渡效果

哪些CSS屬性可以過渡

長度 (padding margin width height  left/top/right/bottom border-width  background-position ...)
顏色
變換
純數字 (opacity、z-index)

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>CSS3過渡</title>
 6     <style>
 7         .box {
 8             width: 100px;
 9             height: 100px;
10             background: red;
11             /*display: block;*/
12             /*visibility: visible;*/
13 
14             border:10px solid purple;
15 
16             
17             /*過渡*/
18             /* transition:3s; */
19             transition-property: width,height;
20             transition-duration: 5s;
21             transition-timing-function: ease;
22             transition-delay:3s;
23 
24 
25             transition: all ease 3s 1s;
26             transition: 4s;
27             transition: all 4s;
28 
29 
30         }
31         .box:hover {
32             /*display: none;*/
33             /*visibility: hidden;*/
34             width: 200px;
35             height: 200px;
36             background: green;
37 
38             border:20px dashed purple;
39 
40         }
41     </style>
42 </head>
43 <body>
44     <h1>transition</h1>
45     <hr>
46     <div class="box">
47         
48     </div>
49 
50     <hr>
51 
52     <p>
53         Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam dolore veritatis, ducimus maxime fugiat unde inventore aspernatur mollitia dolor doloribus facere eum libero repudiandae, quisquam, deserunt facilis magni error! Vero.
54     </p>
55 </body>
56 </html>
過渡
?

觸發過渡

偽類觸發  :hover  :focus  ....
媒體查詢 ? @media
JS
 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>過渡實例</title>
 6     <style>
 7         .item {
 8             display: inline-block;
 9             width: 100px;
10             height: 100px;
11             border: 1px solid #ccc;
12             text-align: center;
13             line-height: 100px;
14             border-radius: 50px;
15             font-size:30px;
16             cursor:pointer;
17             color:#f66700;
18 
19             /*過渡*/
20             transition: transform 1s;
21         }
22 
23         .item:hover {
24             transform: rotate(360deg)
25         }
26     </style>
27 </head>
28 <body>
29     <h1>同志</h1>
30     <hr>
31 
32     <div class="list">
33         <div class="item">1</div>
34         <div class="item">2</div>
35         <div class="item">3</div>
36         <div class="item">4</div>
37         <div class="item">5</div>
38         <div class="item">6</div>
39         <div class="item">7</div>
40         <div class="item">8</div>
41     </div>
42 </body>
43 </html>
過渡實例
?

相關屬性

transition-property  指定要過渡的屬性 用,隔開。默認是 all
transition-duration 過渡持續時間
transition-timing-function 過渡線性效果 默認 ease
transition-delay ? 過渡延遲
transition:property timing-function duration delay

?

  1 <!DOCTYPE html>
  2 <html lang="en">
  3 <head>
  4     <meta charset="UTF-8">
  5     <title>純CSS實現下拉菜單</title>
  6     <style>
  7         * {
  8             padding: 0;
  9             margin: 0;
 10         }
 11         body {
 12             font:14px "Microsoft YaHei",sans-serif;
 13         }
 14         ul {
 15             list-style: none;
 16         }
 17         .container {
 18             margin: 0 auto;
 19             width: 1000px;
 20         }
 21 
 22         .nav {
 23             /*margin-top: 60px;*/
 24             width: 100%;
 25             height: 40px;
 26             line-height: 40px;
 27             background: #333;
 28         }
 29         
 30         /*一級菜單*/ /*該選擇器會選擇 所有li*/
 31         .nav li {
 32             float: left;
 33             position: relative;
 34         }
 35 
 36         /*一級菜單*/
 37         .nav li a {
 38             display: block;
 39             width: 100px;
 40             text-align: center;
 41             color: #fff;
 42             text-decoration: none;
 43         }
 44 
 45         /*二級菜單*/
 46         .nav li ul li a {
 47             color: #333;
 48         }
 49         .nav li ul li {
 50             /*覆蓋前面設置  */
 51             float: none;
 52         }
 53         .nav li ul {
 54             /*border: 1px solid #ccc;
 55             border-top: none;*/
 56             background: #fff;
 57             /*二級菜單先隱藏*/
 58             /*display: none;
 59 */
 60             /*絕對定位*/
 61             position: absolute;
 62             left:0;
 63             top:;
 64             
 65             overflow: hidden;
 66             height: 0px;
 67 
 68             /*過渡*/
 69             transition: height .5s;
 70         }
 71 
 72         
 73         /*劃過那個li 哪個li就變紅*/
 74         .nav li:hover {
 75             background: red;
 76         }
 77         .nav li:hover ul{
 78         /*    display: block;*/
 79             height: 160px;
 80         }
 81 
 82         /*設置banner*/
 83         .banner img {
 84             width: 100%;
 85         }
 86     </style>
 87 </head>
 88 <body>
 89     
 90     <div class="nav">
 91         <div class="container">
 92             <ul>
 93                 <li><a href="#">首頁</a></li>
 94                 <li>
 95                     <a href="#">博客</a>
 96                     <ul>
 97                         <li><a href="#">同志博客</a></li>
 98                         <li><a href="#">小同志博客</a></li>
 99                         <li><a href="#">老同志博客</a></li>
100                         <li><a href="#">大同志博客</a></li>
101                     </ul>
102                 </li>
103                 <li>
104                     <a href="#">論壇</a>
105                     <ul>
106                         <li><a href="#">同志論壇</a></li>
107                         <li><a href="#">紅色論壇</a></li>
108                         <li><a href="#">黃色論壇</a></li>
109                         <li><a href="#">綠色論壇</a></li>
110                     </ul>
111                 </li>
112                 <li><a href="#">關于我們</a></li>
113                 <li>
114                     <a href="#">舉報我們</a>
115                     <ul>
116                         <li><a href="#">涉黃</a></li>
117                         <li><a href="#">涉黑</a></li>
118                         <li><a href="#">涉賭</a></li>
119                         <li><a href="#">涉毒</a></li>
120                     </ul>
121                 </li>
122             </ul>
123         </div>
124     </div>
125 
126 
127     <div class="banner">
128         <img src="../../dist/images_one/meinv02.jpg" alt="">
129     </div>
130 </body>
131 </html>
導航-下拉菜單

?

3.8 CSS3動畫

關鍵幀

@keyframes 動畫名字 {
? ?0% {
? ? ? ?
? }
? ?20% {
? ? ? ?
? }
? ?40% {
? ? ? ?
? }
? ?100% {
? ? ? ?
? }
}

?

相關CSS屬性

animation-name  指定動畫的名字
animation-duration 動畫的執行時間
animation-timing-function 執行效果速度 ?
animation-delay ? 延遲
animation-iteration-count ? 循環 次數 ?infinite(無限)
animation-direction: ?alternate (正向 反向 交替)\ reverse(反向)
animation-play-state: running / paused
animation 復合屬性

?

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>CSS3動畫</title>
 6     <style>
 7         
 8         /*關鍵幀的語法*/
 9         @keyframes myanimate{
10             from {
11                 background: red;
12                 width:200px;
13             }
14 
15             50% {
16                 width:400px;
17             }
18 
19             to {
20                 background: green;
21                 width:600px;
22             }
23         }
24 
25         .box {
26             width: 200px;
27             height: 200px;
28             border: 2px dashed orange;
29 
30             animation-name: myanimate;
31             animation-duration: 1s; /*動畫持續時間*/
32             animation-timing-function: linear;
33             animation-delay: 0s;
34             animation-iteration-count: infinite; /*無限循環*/
35             animation-direction: alternate; /*多次循環的時候,一次正向動畫,一次反向動畫*/
36 
37             animation-play-state: paused;
38 
39             animation: myanimate 2s linear 2 alternate;
40         }
41 
42         .box:hover {
43             animation-play-state: running;
44         }
45     </style>
46 </head>
47 <body>
48     
49     <div class="box"></div>
50 
51 
52 </body>
53 </html>
css3動畫

?

?

?

轉載于:https://www.cnblogs.com/Roc-Atlantis/p/9433519.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/388885.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388885.shtml
英文地址,請注明出處:http://en.pswp.cn/news/388885.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

webservice 啟用代理服務器

您會發現你寫完了一個webservice在調用的時候發現怎也沒辦法調用&#xff0c;一個簡單的webservice怎么不能使用&#xff0c;一肚子的怨恨&#xff0c;哈哈您可能沒有為webservice設置代理。 下面就給您寫個調用的用例和大家分享下。其實很簡單&#xff0c;但是你沒有想到的時…

mysql常用的存儲引擎_Mysql存儲引擎

什么是存儲引擎&#xff1f;關系數據庫表是用于存儲和組織信息的數據結構&#xff0c;可以將表理解為由行和列組成的表格&#xff0c;類似于Excel的電子表格的形式。有的表簡單&#xff0c;有的表復雜&#xff0c;有的表根本不用來存儲任何長期的數據&#xff0c;有的表讀取時非…

android studio設計模式和文本模式切換

轉載于:https://www.cnblogs.com/judes/p/9437104.html

高斯模糊為什么叫高斯濾波_為什么高斯是所有發行之王?

高斯模糊為什么叫高斯濾波高斯分布及其主要特征&#xff1a; (Gaussian Distribution and its key characteristics:) Gaussian distribution is a continuous probability distribution with symmetrical sides around its center. 高斯分布是連續概率分布&#xff0c;其中心周…

C# webbrowser 代理

百度&#xff0c;google加自己理解后&#xff0c;將所得方法總結一下&#xff1a; 方法1&#xff1a;修改注冊表Software//Microsoft//Windows//CurrentVersion//Internet Settings下 ProxyEnable和ProxyServer。這種方法適用于局域網用戶&#xff0c;撥號用戶無效。 1p…

C MySQL讀寫分離連接串_Mysql讀寫分離

一 什么是讀寫分離MySQL Proxy最強大的一項功能是實現“讀寫分離(Read/Write Splitting)”。基本的原理是讓主數據庫處理事務性查詢&#xff0c;而從數據庫處理SELECT查詢。數據庫復制被用來把事務性查詢導致的變更同步到集群中的從數據庫。當然&#xff0c;主服務器也可以提供…

golang 編寫的在線redis 內存分析工具 rma4go

redis 內存分析工具 rma4go redis是一個很有名的內存型數據庫&#xff0c;這里不做詳細介紹。而rma4go (redis memory analyzer for golang) 是一個redis的內存分析工具&#xff0c;這個工具的主要作用是針對運行時期的redis進行內存的分析&#xff0c;統計redis中key的分布情…

從Jupyter Notebook到腳本

16 Aug: My second article: From Scripts To Prediction API8月16日&#xff1a;我的第二篇文章&#xff1a; 從腳本到預測API As advanced beginners, we know quite a lot: EDA, ML concepts, model architectures etc…… We can write a big Jupyter Notebook, click “Re…

【EasyNetQ】- 使用Future Publish調度事件

許多業務流程要求在將來某個日期安排事件。例如&#xff0c;在與客戶進行初次銷售聯系后&#xff0c;我們可能希望在將來的某個時間安排跟進電話。EasyNetQ可以通過其Future Publish功能幫助您實現此功能。例如&#xff0c;這里我們使用FuturePublish擴展方法來安排未來一個月的…

Java這些多線程基礎知識你會嗎?

0、并發和并行、進程核線程、多進程和多線程的區別&#xff1a; &#xff08;這里的時間和時刻上的概念同物理上的一樣&#xff09; 并發&#xff1a;在一段時間內多個任務同時執行&#xff0c;或者說是在一段很短的時間內可以執行多條程序指令&#xff0c;微觀上看起來好像是可…

MySQL set names 命令_mysql set names 命令和 mysql 字符編碼問題

先看下面的執行結果&#xff1a;(rootlocalhost)[(none)]mysql>show variables like character%;---------------------------------------------------------------------------------------| Variable_name | Value |---------------------------------------------------…

設置Proxy Server和SQL Server實現數據庫安全

首先&#xff0c;我們需要了解一下SQL Server在WinSock上定義協議的步驟&#xff1a; 1. 在”啟動”菜單上&#xff0c;指向”程序/Microsoft Proxy Server”&#xff0c;然后點擊”Microsoft Management Console”。 2. 展開”Internet Information Service”,再展開運行Proxy…

Python django解決跨域請求的問題

解決方案 1.安裝django-cors-headers pip3 install django-cors-headers 2.配置settings.py文件 INSTALLED_APPS [...corsheaders&#xff0c;...] MIDDLEWARE_CLASSES (...corsheaders.middleware.CorsMiddleware,django.middleware.common.CommonMiddleware, # 注意順序...…

加勒比海兔_加勒比海海洋物種趨勢

加勒比海兔Ok, here’s a million dollar question: is the Caribbean really dying? Or, more specifically, are marine species found on Caribbean reefs becoming less abundant?好吧&#xff0c;這是一個百萬美元的問題&#xff1a;加勒比海真的死了嗎&#xff1f; 或者…

mysql 查出相差年數_MySQL計算兩個日期相差的天數、月數、年數

MySQL自帶的日期函數TIMESTAMPDIFF計算兩個日期相差的秒數、分鐘數、小時數、天數、周數、季度數、月數、年數&#xff0c;當前日期增加或者減少一天、一周等等。SELECT TIMESTAMPDIFF(類型,開始時間,結束時間)相差的秒數&#xff1a;SELECT TIMESTAMPDIFF(SECOND,1993-03-23 0…

tornado 簡易教程

引言 回想Django的部署方式 以Django為代表的python web應用部署時采用wsgi協議與服務器對接&#xff08;被服務器托管&#xff09;&#xff0c;而這類服務器通常都是基于多線程的&#xff0c;也就是說每一個網絡請求服務器都會有一個對應的線程來用web應用&#xff08;如Djang…

如果你的電腦是通過代理上網的.就要用端口映射

由于公網IP地址有限&#xff0c;不少ISP都采用多個內網用戶通過代理和網關路由共用一個公網IP上INTERNET的方法&#xff0c; 這樣就限制了這些用戶在自己計算機上架設個人網站&#xff0c;要實現在這些用戶端架設網站&#xff0c;最關鍵的一點是&#xff0c; 怎樣把多用戶的內網…

人口密度可視化_使用GeoPandas可視化菲律賓的人口密度

人口密度可視化GeoVisualization /菲律賓。 (GeoVisualization /Philippines.) Population density is a crucial concept in urban planning. Theories on how it affects economic growth are divided. Some claim, as Rappaport does, that an economy is a form of “spati…

Unity - Humanoid設置Bip骨骼導入報錯

報錯如下&#xff1a; 解決&#xff1a; 原因是biped骨骼必須按照Unity humanoid的要求設置&#xff0c;在max中設置如下&#xff1a; 轉載于:https://www.cnblogs.com/CloudLiu/p/10746052.html

python3openpyxl無法打開文件_Python3 處理excel文件(openpyxl庫)

openpyxl 介紹openpyxl是一個用于讀/寫 XLSX/XLSM/XLTX/XLTM文件的python庫。openpyxl(可讀寫excel表)專門處理Excel2007及以上版本產生的xlsx文件&#xff1b;2007一下的版本為xls后綴的文件&#xff0c;需要使用 xlrd和xlwt庫進行操作。雖然xlrd和xlwt也可以進行文件讀寫&…