nth-child()選擇器css
:empty選擇器能夠用做爲購物車沒有商品的時候不顯示數字圖標html
::before和::after前端
內容css3
/*也能夠這樣使用*/ .main .item:after { content: attr(data-brief); display: block; width: 100%; height: 100%; text-align: center; line-height: 210px; position: absolute; top: 0; left: 0; color: #FFF; font-family: '微軟雅黑'; font-size: 18px; background-color: rgba(170, 170, 170, 0); z-index: -1; transition: all 0.3s ease-in; }
li::before { content: 'itcast'; /*display: block;*/ width: 100px; height: 100px; background-color: blue; } li::after { content: ''; /*display: block;*/ width: 100px; height: 100px; background-color: pink; } .add { display: block; width: 100px; height: 100px; background-color: yellow; }
text-shadow屬性瀏覽器
可分別設置偏移量、模糊度、顏色(可設透明度)。curl
實現效果wordpress
body { background-color: gray; font: bold 6em "microsoft yahei"; } div { margin: 30px; color: #808080; text-align: center; } .to { text-shadow: -1px -1px #FFF, 1px 1px #000; } .ao { text-shadow: 1px 1px 0px #FFF, -1px -1px 0px #000; }
/*使用方法和文字陰影同樣,也能夠設置多個陰影*/ .item:nth-child(5) { box-shadow: 2px 2px 10px #CCC, 4px 4px 4px blue, inset 8px 8px 10px red; }
多屬性寫法佈局
box-sizing: content-box;
:默認計算方式 content = width => (盒子大小=width + padding + border)box-sizing: border-box;
:計算方式 content = width - padding - border => (盒子大小= width - padding - border + padding + border)
動畫效果post
transparent屬性值,不可調節透明度,始終徹底透明學習
.inner { width: 0px; height: 0px; border-width:20px; border-style:solid; border-color:red transparent transparent transparent background: transparent; }
background: rgba(255, 255, 255, 0.5);
background-color: hsla(360, 50%, 50%, .5);
方向說明
直線
background: linear-gradient(to right, yellow, green)
角度
background: linear-gradient(45deg, yellow, green)
漸進範圍說明
background: linear-gradient( 90deg, yellow 25%, green 25%, green 50%, blue 50%, blue 75%, pink 75%, pink 100% );
賦值給background-image
代碼實現藉助透明屬性值和背景來實現的
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>CSS3 漸變</title> <style> body { margin: 0; padding: 0; background-color: #CCC; } .linear:nth-child(1) { width: 1000px; height: 100px; margin: 100px auto; background-color: #FFF; background-image: linear-gradient( 135deg, black 25%, transparent 25%, transparent 50%, black 50%, black 75%, transparent 75% ); /*background-repeat: no-repeat;*/ background-size: 100px 100px; animation: move 1s linear infinite; } /*定義動畫序列*/ @keyframes move { from {} to { background-position: 100px 0; } } </style> </head> <body> <div class="linear"></div> </body> </html>
.radial { width: 300px; height: 300px; margin: 100px auto; /*位置給英文*/ background-image: radial-gradient(120px at left top, yellow, green); /*位置能夠是百分比和數值*/ background-image: radial-gradient(120px 80px at 100% 100%, yellow, green); /*輻射範圍能夠是橢圓*/ background-image: radial-gradient(120px 80px at center center, yellow, green); /*能夠給多個漸變色和漸變色位置*/ background-image: radial-gradient(120px at center center, yellow, green, blue, pink); background-image: radial-gradient(120px at center center, yellow 25%, green 45%, blue, pink); }
效果實現
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>CSS3 漸變</title> <style> body { margin: 0; padding: 0; background-color: #F7F7F7; } .radial-gradient { width: 200px; height: 200px; margin: 40px auto; border-radius: 100px; background-color: blue; background-image: radial-gradient( 200px at 50px 60px, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.6) ); } </style> </head> <body> <div class="radial-gradient"></div> </body> </html>
// 進入的時候有動畫,離開的時候沒動畫,加載上面就是進入和離開的時候都有動畫 .transition { width: 200px; height: 200px; margin: 50px auto; background-color: green; } .transition:hover { transition: all 3s; background-color: yellow; }
transition:屬性 時間 延遲 速度
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>百度LOGO</title> <style> body { margin: 0; padding: 0; background-color: #F7F7F7; } .logo { width: 270px; height: 129px; margin: 100px auto; background-image: url(./baidu.png); background-position: 0 0; } </style> </head> <body> <div class="logo"></div> <script> var logo = document.querySelector('.logo'); var offset = -270; var n = 0; setInterval(function () { n++; logo.style.backgroundPosition = offset * n + 'px 0px'; if(n >= 64) n = 0; }, 100); </script> </body> </html>
transform: translate(400px, 0) rotate(360deg) scale(2);
,☆☆☆其順序會影響轉換的效果。☆☆☆
transform-origin能夠調整元素轉換的原點,主要用於rotate,對於transform: translate(x,y) 沒有影響。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>drop-shadows</title> <style> body { font: 14px/1.5 Arial, sans-serif; padding: 20px 0 0; text-align: center; color: #333; background: #ccc; } .drop-shadow { position: relative; width: 45%; padding: 14px; margin: 28px auto 70px; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset; } .drop-shadow:before, .drop-shadow:after { content: ""; position: absolute; z-index: -2; bottom: 15px; left: 10px; width: 50%; height: 20%; } .drop-shadow:after { right: 10px; left: auto; } .round { border-radius: 4px; } .round:before, .round:after { max-width: 300px; box-shadow: 0 15px 10px rgba(0, 0, 0, 0.7); transform: rotate(-3deg); } .round:after { transform: rotate(3deg); } .curls { border: 1px solid #efefef; border-radius: 0 0 120px 120px / 0 0 6px 6px; } .curls:before, .curls:after { bottom: 12px; max-width: 200px; height: 55%; box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4); transform: skew(-8deg) rotate(-4deg); } .curls:after { transform: skew(8deg) rotate(4deg); } .perspective:before { left: 28px; bottom: 8px; max-width: 200px; height: 35%; box-shadow: -60px 5px 8px rgba(0, 0, 0, 0.4); transform: skew(50deg); } .perspective:after { display: none; } .raised:before { width: auto; right: 10px; left: 10px; bottom: 0; box-shadow: 0 8px 10px rgba(0, 0, 0, 0.5); } </style> </head> <body> <div class="drop-shadow round"> <h1>CSS drop-shadows without images</h1> <p>No extra markup, fluid, all modern browsers</p> </div> <div class="drop-shadow curls"> <h1>Some curls</h1> <p>No extra markup, all modern browsers</p> </div> <div class="drop-shadow perspective"> <h1>Some perspective</h1> <p>No extra markup, all modern browsers</p> </div> <div class="drop-shadow raised"> <h1>Raised box</h1> <p>No extra markup, all modern browsers</p> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>CSS3 3D轉換</title> <style> body { margin: 0; padding: 0; background-color: #B3C04C; } .wallet { width: 300px; height: 300px; margin: 50px auto; position: relative; transform-style: preserve-3d; transition: all 10s; } .wallet::before, .wallet::after { content: ''; position: absolute; left: 0; top: 0; display: block; width: 100%; height: 100%; background-image: url(./images/bg.png); background-repeat: no-repeat; } .wallet::before { background-position: right top; transform: rotateY(180deg); } .wallet::after { background-position: left top; /*backface-visibility: hidden;*/ transform: translateZ(2px); } .wallet:hover { transform: rotateY(180deg); } </style> </head> <body> <div class="wallet"></div> </body> </html>
perspective:1000px
transform: perspective(400px) translateZ(200px);
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>CSS 3D轉換</title> <style> body { margin: 0; padding: 0; background-color: #F7F7F7; } .box { width: 200px; height: 200px; text-align: center; line-height: 200px; font-size: 24px; margin: 100px auto; position: relative; transform: rotateY(30deg) rotateX(-30deg); transform-style: preserve-3d; animation: rotate 8s linear infinite; } .front, .back, .left, .right, .top, .bottom { width: 200px; height: 200px; /*關鍵點是讓幾個面重合,這樣座標系能夠統一*/ position: absolute; top: 0; left: 0; /*給透明度是爲了能夠看到後面的面*/ /*opacity: 0.5;*/ } .front { background-color: pink; transform: rotateY(0) translateZ(100px); } .back { background-color: blue; transform: translateZ(-100px); } .left { background-color: green; transform: rotateY(90deg) translateZ(-100px); } .right { background-color: yellow; transform: rotateY(90deg) translateZ(100px); } .top { background-color: red; transform: rotateX(90deg) translateZ(100px); } .bottom { background-color: orange; transform: rotateX(90deg) translateZ(-100px); } @keyframes rotate { from { transform: rotateX(0) rotateY(360deg); } to { transform: rotateX(360deg) rotateY(0); } } </style> </head> <body> <div class="box"> <div class="front">front</div> <div class="back">back</div> <div class="left">left</div> <div class="right">right</div> <div class="top">top</div> <div class="bottom">bottom</div> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>CSS3 3D轉換</title> <style> body { margin: 0; padding: 0; font-family: '微軟雅黑'; background-color: #F7F7F7; } .nav { height: 40px; margin-top: 50px; text-align: center; list-style: none; } li { width: 120px; height: 40px; float: left; position: relative; transition: all 1s; transform-style: preserve-3d; } li span { height: 100%; width: 100%; line-height: 40px; position: absolute; left: 0; top: 0; } li span:nth-child(1) { transform: translateZ(20px); background: green; } li span:nth-child(2) { transform: rotateX(90deg) translateZ(20px); background: yellow; } li:hover { transform: rotateX(-90deg); } </style> </head> <body> <ul class="nav"> <li> <span>Web前端</span> <span>石國慶</span> </li> <li> <span>Web前端</span> <span>石國慶</span> </li> <li> <span>Web前端</span> <span>石國慶</span> </li> <li> <span>Web前端</span> <span>石國慶</span> </li> </ul> </body> </html>
擴展:兩種設置撐滿全屏的方法,下面的寫法用的比較多 width: 100%; height: 100%; position: absolute; top: 0; left: 0; right:0; bottom:0;
.arms { width: 340px; background-color: #A4CA39; border-radius: 25px; 方法一 test-align:center; // 垂直方向兩條基線對齊 vertual-align:center; 方法二 position: absolute; left:50%; top:50%; 寬度的一半 這樣有問題,當盒子變化的時候有問題,因此推薦你們用方法3 margin:-170px 0 0 -170px; 方法三 position: absolute; left:50%; top:50%; 寬度的一半 /*位移時設置百分比,相對盒子的大小和原來的位置*/ transform: translate(-50%, -50%); }