按钮悬停边框和背景动画集合

栏目: Html · 发布时间: 5年前

核心属性

opacity: .999 使元素产生一个层叠上下文,这样按钮6和8的动画就不会被背景遮盖住了

left/top: -1px 使伪元素与按钮的位置重合,原因在下方

transition-delay 横向与纵向边框动画产生细微的延时效果

z-index: -1 防止动画产生的颜色块盖住按钮的文字

设置了left/top/right/bottom的absolute元素,是相对于父元素的padding-box进行定位的,所以这里伪元素要移动一个边框的距离,才能与按钮的位置重合,否则会出现下面的效果:

按钮悬停边框和背景动画集合

可以看到,绿色边框和灰色边框有1px的距离

  1. <div class="main-container">
  2. <section>
  3. <button class="btn btn-green btn-border-o">按钮一</button>
  4. <button class="btn btn-blue btn-border">按钮二</button>
  5. <button class="btn btn-purple btn-border-rev-o">按钮三</button>
  6. <button class="btn btn-navy btn-border-rev">按钮四</button>
  7. </section>
  8. <section>
  9. <button class="btn btn-orange btn-fill-vert-o">按钮五</button>
  10. <button class="btn btn-red btn-fill-vert">按钮六</button>
  11. <button class="btn btn-green btn-fill-horz-o">按钮七</button>
  12. <button class="btn btn-blue btn-fill-horz">按钮八</button>
  13. </section>
  14. </div>
  1. *, *:before, *:after {
  2. transition: all 0.3s;
  3. }
  4. section {
  5. position: relative;
  6. padding: 5px 0 5px;
  7. text-align: center;
  8. }
  9. .btn {
  10. position: relative;
  11. display: inline-block;
  12. line-height: 35px;
  13. margin: 8px;
  14. padding: 0 15px;
  15. font-size: 15px;
  16. border-radius: 3px;
  17. opacity: .999;
  18. cursor: pointer;
  19. }
  20. .btn-border-o {
  21. background-color: transparent;
  22. border: 1px solid #d0d0d0;
  23. color: #B8B8B8;
  24. }
  25. .btn-border-o:before, .btn-border-o:after {
  26. content: '';
  27. position: absolute;
  28. border-style: solid;
  29. border-radius: 3px;
  30. box-sizing: content-box;
  31. }
  32. .btn-border-o:before {
  33. left: 0;
  34. top: -1px;
  35. width: 0;
  36. height: 100%;
  37. border-width: 1px 0 1px 0;
  38. transition-delay: 0.05s;
  39. }
  40. .btn-border-o:after {
  41. top: 0;
  42. left: -1px;
  43. width: 100%;
  44. height: 0;
  45. border-width: 0 1px 0 1px;
  46. }
  47. .btn-border-o:hover:before {
  48. width: 100%;
  49. }
  50. .btn-border-o:hover:after {
  51. height: 100%;
  52. }
  53. .btn-border-o.btn-green:before, .btn-border-o.btn-green:after {
  54. border-color: #2ecc71;
  55. }
  56. .btn-border-o.btn-green:hover {
  57. color: #2ecc71;
  58. }
  59. .btn-border {
  60. background-color: #e5e5e5;
  61. border: 1px solid #e5e5e5;
  62. color: #a6a6a6;
  63. }
  64. .btn-border:before, .btn-border:after {
  65. position: absolute;
  66. content: '';
  67. border-style: solid;
  68. border-radius: 3px;
  69. box-sizing: content-box;
  70. }
  71. .btn-border:before {
  72. top: -1px;
  73. left: 0;
  74. width: 0;
  75. height: 100%;
  76. border-width: 1px 0 1px 0;
  77. transition-delay: 0.05s;
  78. }
  79. .btn-border:after {
  80. top: 0;
  81. left: -1px;
  82. width: 100%;
  83. height: 0;
  84. border-width: 0 1px 0 1px;
  85. }
  86. .btn-border:hover {
  87. background-color: transparent;
  88. }
  89. .btn-border:hover:before {
  90. width: 100%;
  91. }
  92. .btn-border:hover:after {
  93. height: 100%;
  94. }
  95. .btn-border.btn-blue:before, .btn-border.btn-blue:after {
  96. border-color: #3498db;
  97. }
  98. .btn-border.btn-blue:hover {
  99. color: #3498db;
  100. }
  101. .btn-border-rev-o {
  102. background-color: transparent;
  103. border: 1px solid #d0d0d0;
  104. color: #B8B8B8;
  105. }
  106. .btn-border-rev-o:before, .btn-border-rev-o:after {
  107. content: '';
  108. position: absolute;
  109. border-style: solid;
  110. border-radius: 3px;
  111. box-sizing: content-box;
  112. }
  113. .btn-border-rev-o:before {
  114. top: -1px;
  115. right: 0;
  116. width: 0;
  117. height: 100%;
  118. border-width: 1px 0 1px 0;
  119. transition-delay: 0.05s;
  120. }
  121. .btn-border-rev-o:after {
  122. left: -1px;
  123. bottom: 0;
  124. width: 100%;
  125. height: 0;
  126. border-width: 0 1px 0 1px;
  127. }
  128. .btn-border-rev-o:hover:before {
  129. width: 100%;
  130. }
  131. .btn-border-rev-o:hover:after {
  132. height: 100%;
  133. }
  134. .btn-border-rev-o.btn-purple:before, .btn-border-rev-o.btn-purple:after {
  135. border-color: #9b59b6;
  136. }
  137. .btn-border-rev-o.btn-purple:hover {
  138. color: #9b59b6;
  139. }
  140. .btn-border-rev {
  141. background-color: #e5e5e5;
  142. border: 1px solid #e5e5e5;
  143. color: #a6a6a6;
  144. }
  145. .btn-border-rev:before, .btn-border-rev:after {
  146. content: '';
  147. position: absolute;
  148. border-style: solid;
  149. border-radius: 3px;
  150. box-sizing: content-box;
  151. }
  152. .btn-border-rev:before {
  153. top: -1px;
  154. right: 0;
  155. width: 0;
  156. height: 100%;
  157. border-width: 1px 0 1px 0;
  158. }
  159. .btn-border-rev:after {
  160. bottom: 0;
  161. left: -1px;
  162. width: 100%;
  163. height: 0;
  164. border-width: 0 1px 0 1px;
  165. transition-delay: 0.05s;
  166. }
  167. .btn-border-rev:hover {
  168. background-color: transparent;
  169. }
  170. .btn-border-rev:hover:before {
  171. width: 100%;
  172. }
  173. .btn-border-rev:hover:after {
  174. height: 100%;
  175. }
  176. .btn-border-rev.btn-navy:before, .btn-border-rev.btn-navy:after {
  177. border-color: #34495e;
  178. }
  179. .btn-border-rev.btn-navy:hover {
  180. color: #34495e;
  181. }
  182. .btn-fill-vert-o {
  183. background-color: transparent;
  184. border: 1px solid #d0d0d0;
  185. color: #B8B8B8;
  186. overflow: hidden;
  187. }
  188. .btn-fill-vert-o:before, .btn-fill-vert-o:after {
  189. content: '';
  190. position: absolute;
  191. left: 0;
  192. width: 100%;
  193. height: 0;
  194. opacity: 0;
  195. z-index: -1;
  196. }
  197. .btn-fill-vert-o:before {
  198. top: 50%;
  199. }
  200. .btn-fill-vert-o:after {
  201. bottom: 50%;
  202. }
  203. .btn-fill-vert-o:hover {
  204. color: #fff;
  205. }
  206. .btn-fill-vert-o:hover:before, .btn-fill-vert-o:hover:after {
  207. height: 50%;
  208. opacity: 1;
  209. }
  210. .btn-fill-vert-o.btn-orange:before, .btn-fill-vert-o.btn-orange:after {
  211. background-color: #e67e22;
  212. }
  213. .btn-fill-vert-o.btn-orange:hover {
  214. border-color: #e67e22;
  215. }
  216. .btn-fill-vert {
  217. background-color: #e5e5e5;
  218. border: 1px solid #e5e5e5;
  219. color: #a6a6a6;
  220. overflow: hidden;
  221. }
  222. .btn-fill-vert:before, .btn-fill-vert:after {
  223. content: '';
  224. position: absolute;
  225. width: 100%;
  226. height: 0;
  227. opacity: 0;
  228. left: 0;
  229. z-index: -1;
  230. }
  231. .btn-fill-vert:before {
  232. top: 50%;
  233. }
  234. .btn-fill-vert:after {
  235. bottom: 50%;
  236. }
  237. .btn-fill-vert:hover {
  238. color: #fff;
  239. }
  240. .btn-fill-vert:hover:before, .btn-fill-vert:hover:after {
  241. height: 50%;
  242. opacity: 1;
  243. }
  244. .btn-fill-vert.btn-red:before, .btn-fill-vert.btn-red:after {
  245. background-color: #e74c3c;
  246. }
  247. .btn-fill-vert.btn-red:hover {
  248. border-color: #e74c3c;
  249. }
  250. .btn-fill-horz-o {
  251. background-color: transparent;
  252. border: 1px solid #d0d0d0;
  253. color: #B8B8B8;
  254. overflow: hidden;
  255. }
  256. .btn-fill-horz-o:before, .btn-fill-horz-o:after {
  257. content: '';
  258. position: absolute;
  259. top: 0;
  260. width: 0;
  261. height: 100%;
  262. opacity: 0;
  263. z-index: -1;
  264. }
  265. .btn-fill-horz-o:before {
  266. left: 50%;
  267. }
  268. .btn-fill-horz-o:after {
  269. right: 50%;
  270. }
  271. .btn-fill-horz-o:hover {
  272. color: #fff;
  273. }
  274. .btn-fill-horz-o:hover:before, .btn-fill-horz-o:hover:after {
  275. width: 50%;
  276. opacity: 1;
  277. }
  278. .btn-fill-horz-o.btn-green:before, .btn-fill-horz-o.btn-green:after {
  279. background-color: #2ecc71;
  280. }
  281. .btn-fill-horz-o.btn-green:hover {
  282. border-color: #2ecc71;
  283. }
  284. .btn-fill-horz {
  285. background-color: #e5e5e5;
  286. border: 1px solid #e5e5e5;
  287. color: #a6a6a6;
  288. overflow: hidden;
  289. }
  290. .btn-fill-horz:before, .btn-fill-horz:after {
  291. content: '';
  292. position: absolute;
  293. top: 0;
  294. width: 0;
  295. height: 100%;
  296. opacity: 0;
  297. z-index: -1;
  298. }
  299. .btn-fill-horz:before {
  300. left: 50%;
  301. }
  302. .btn-fill-horz:after {
  303. right: 50%;
  304. }
  305. .btn-fill-horz:hover {
  306. color: #fff;
  307. }
  308. .btn-fill-horz:hover:before, .btn-fill-horz:hover:after {
  309. width: 50%;
  310. opacity: 1;
  311. }
  312. .btn-fill-horz.btn-blue:before, .btn-fill-horz.btn-blue:after {
  313. background-color: #3498db;
  314. }
  315. .btn-fill-horz.btn-blue:hover {
  316. border-color: #3498db;
  317. }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

About Face 3 交互设计精髓

About Face 3 交互设计精髓

Alan Cooper、Robert Reimann、David Cronin / 刘松涛 / 电子工业出版社 / 2008-11 / 72.00元

本书是一本数字产品和系统的交互设计指南,全面系统地讲述了交互设计过程、原理和方法,涉及的产品和系统有个人电脑上的个人和商务软件、Web应用、手持设备、信息亭、数字医疗系统、数字工业系统等。运用本书的交互设计过程和方法,有助于了解使用者和产品之间的交互行为,进而更好地设计出更具吸引力和更具市场竞争力的产品。 全书分成3篇:第1篇描述了“目标导向设计”,详细讨论了用户和设计的过程及思想;第2篇讲......一起来看看 《About Face 3 交互设计精髓》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器