Home Web Front-end HTML Tutorial CSS3实现的鼠标悬浮开门关门效果代码实例_html/css_WEB-ITnose

CSS3实现的鼠标悬浮开门关门效果代码实例_html/css_WEB-ITnose

Jun 24, 2016 am 11:27 AM

CSS3实现的鼠标悬浮开门关门效果代码实例:
本章节分享一段代码实例,它利用CSS3模拟实现了简单的开门关门效果。
代码实例如下:

<!DOCTYPE html><html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>蚂蚁部落</title><style>.door{   position:relative;   width:400px;   height:300px;   overflow:hidden;   border:2px solid #000;   background:#000;}.door:before,.door:after{   content:'';   position:absolute;   left:0;   width:0;   height:0;   overflow:hidden;   border-color:#000 transparent transparent transparent;   border-style:solid;   border-width:0 200px;   z-index:2;   transition:all .8s ease;}.door:before{top:0;}.door:after{   bottom:0;   border-color:transparent transparent #000 transparent;}.door:hover:before,.door:hover:after{border-width:40px 200px;}.door-left, .door-right{   position:relative;   float:left;   width:50%;   height:100%;   background:#f00;   box-sizing:border-box;   transition:all .5s ease;}.door-left{   border-right:2px solid #000;   -webkit-transform-origin:0 0; } .door-left:before,.door-right:before{    content:'';    position:absolute;    width:10px;    height:10px;    top:50%;    margin-top:-5px;    border-radius:50%;    background:#000; } .door-left:before{right:5px;} .door-right:before{left:5px;} .door-right{    border-left:2px solid #000;    -webkit-transform-origin:100% 0; } .door:hover .door-left{    -webkit-transform:rotateY(-90deg);      transition:all .8s ease-out; } .door:hover .door-right{    -webkit-transform:rotateY(90deg);      transition:all .8s ease-out; }</style></head><body><div class="door">  <div class="door-left"></div>  <div class="door-right"></div></div></body></html>
Copy after login

上面的代码实现了我们的要求,代码根本无需过多介绍,只需要明白各个属性的原理就可以了。
相关阅读:
(1).border-color属性可以参阅css3的border-color用法详解一章节。
(2).transition可以参阅CSS3的transition属性详解一章节。
(3).:before可以参阅CSS的伪对象选择符before/E::before一章节。
(4).border-radius可以参阅CSS3实现圆角效果一章节。

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=18180

更多内容可以参阅:http://www.softwhy.com/divcss/

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update? Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update? Mar 04, 2025 pm 12:32 PM

Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?

How do I use HTML5 form validation attributes to validate user input? How do I use HTML5 form validation attributes to validate user input? Mar 17, 2025 pm 12:27 PM

How do I use HTML5 form validation attributes to validate user input?

What is the purpose of the <iframe> tag? What are the security considerations when using it? What is the purpose of the <iframe> tag? What are the security considerations when using it? Mar 20, 2025 pm 06:05 PM

What is the purpose of the <iframe> tag? What are the security considerations when using it?

How to efficiently add stroke effects to PNG images on web pages? How to efficiently add stroke effects to PNG images on web pages? Mar 04, 2025 pm 02:39 PM

How to efficiently add stroke effects to PNG images on web pages?

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

What is the purpose of the <meter> element?

What are the best practices for cross-browser compatibility in HTML5? What are the best practices for cross-browser compatibility in HTML5? Mar 17, 2025 pm 12:20 PM

What are the best practices for cross-browser compatibility in HTML5?

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

What is the purpose of the <datalist> element?

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

What is the purpose of the <progress> element?

See all articles