准備換工作了,周末在家充電,本來想封裝個插件的。
但是看到個有意思的博文,原作者處理的不是很好,感覺有點意思我就研究一下。
原文地址:http://www.cnblogs.com/yexiaochai/archive/2013/05/18/3085536.html
我完成的效果預覽:http://jsfiddle.net/dtdxrk/cbSfX/embedded/result/
第一題:使用 HTML+CSS 實現如圖布局,border-widht 5px,一個格子大小是 50*50,hover時候邊框變為紅色(兼容IE6+,考慮語義化的結構)
簡單分析一下:這題沒什么好說的項目開發時經常用到的效果 a元素塊級化 :hover的時候相對定位 改變z-index
第二題:使用一個標簽和純CSS <a href="#" title="訂閱博客">訂閱博客</a> 實現如圖效果,文字始終保持左邊距10px, 下邊距5px,改變字體大小(12px-50px)時,邊距保持不變,不使用 content:"訂閱博客",兼容現代瀏覽器
其實第二題挺有意思的,需要完成兩個動畫效果:
1.只能用一個元素 a 如果你display:block塊級化 就不能改變文字的位置了 所以使用display:table-cell 就可以使用vertical-align:bottom
2.文字放大動畫 用的是CSS3 Transition
3.鼠標放上去有個背景顏色的改變動畫 用到了CSS3 Animation 目前Firefox還不支持
總結:
1.淘寶ued確實牛 兩道題短小精干
2.由於各個瀏覽器的兼容問題 都沒有看過css3 又走別人后面了
相關學習地址:
CSS3 Transition :http://www.w3cplus.com/content/css3-transition
CSS3 Animation :http://www.w3cplus.com/content/css3-animation
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>css淘寶測試練習題</title> 6 <style type="text/css"> 7 *{margin: 0;padding: 0;font-size: 12px;line-height: 1;font-family: 'Microsoft Yahei',Arial;} 8 h1{background-color: green;color: #fff;padding: 10px;font-size: 16px;font-weight: normal;} 9 a{text-decoration: none;} 10 11 #box1{width:180px;height:180px;overflow: hidden;} 12 #box1 a{display: block;float:left;z-index:1;border: 5px solid blue;margin-right: -5px; margin-bottom:-5px;width: 50px;height: 50px;line-height: 50px;text-align: center;} 13 #box1 a:hover{border-color: red;position: relative;z-index: 2;} 14 15 #box2{ text-align: left;width: 500px;height:100px;padding-left: 10px;padding-bottom: 5px; display:table-cell; vertical-align:bottom;border-bottom: 3px solid red;background-color: #a0d0e0;color: #000;transition: font-size 4s;} 16 #box2:hover{background-color: #a0d0e0;-webkit-animation-name:'wobble';-webkit-animation-duration:0.3s;font-size: 50px;} 17 @-webkit-keyframes 'wobble' { 18 50% { 19 background: green; 20 } 21 100% { 22 background: #a0d0e0; 23 } 24 } 25 </style> 26 </head> 27 <body> 28 <h1>一.使用 HTML+CSS 實現如圖布局,border-widht 5px,一個格子大小是 50*50,hover時候邊框變為紅色(兼容IE6+,考慮語義化的結構)</h1> 29 <img src="https://images0.cnblogs.com/blog/294743/201305/18155307-5204bc8ef6164feb87953dd7f264158b.gif"> 30 <div id="box1"> 31 <a href="#">1</a> 32 <a href="#">2</a> 33 <a href="#">3</a> 34 <a href="#">4</a> 35 <a href="#">5</a> 36 <a href="#">6</a> 37 <a href="#">7</a> 38 <a href="#">8</a> 39 <a href="#">9</a> 40 </div> 41 42 43 <h1>二.使用一個標簽和純CSS a href="#" title="訂閱博客" 訂閱博客 a 實現如圖效果,文字始終保持左邊距10px, 下邊距5px,改變字體大小(12px-50px)時,邊距保持不變,不使用 content:"訂閱博客",兼容現代瀏覽器</h1> 44 <img src="https://images0.cnblogs.com/blog/294743/201305/18155433-83a8a694edc3490d81efde98cc3b09b2.gif"> 45 46 <a href="#" id="box2" title="訂閱博客">訂閱博客</a> 47 48 </body> 49 </html>