本篇文章給大家分享的是有關使用CSS怎么實現一個圖片動畫特效,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
HTML代碼
<!-- 主容器 --> <div class="box"> <!-- 圖片 --> <img src="images/pic.png" alt=""/> <!-- 內容 --> <div class="box-inner-content"> <h4 class="title">Rabbit</h4> <span class="post">Web Developer</span> </div> </div>
CSS代碼
/* 初始化 */
body,
html {
font-size: 100%;
}
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background: #494A5F;
font-weight: 500;
font-size: 1.05em;
font-family: "Microsoft YaHei","Segoe UI", "Lucida Grande", Helvetica, Arial,sans-serif;
}
/* 外層容器 */
.box {
margin: 100px auto;
width: 400px;
height: 400px;
overflow: hidden;
position: relative;
}
.box:before {
content: "";
display: block;
border: 30px solid rgba(255, 255, 255, 0.3);
position: absolute;
top: 5px;
left: 5px;
bottom: 5px;
right: 5px;
opacity: 1;
z-index: 2;
transition: all 0.3s ease 0s;
}
.box:hover:before {
top: 0;
left: 0;
right: 0;
bottom: 0;
border: 10px solid rgba(255, 255, 255, 0.18);
}
.box:after {
content: "";
display: block;
border: 8px solid #fff;
position: absolute;
top: 35px;
left: 35px;
bottom: 35px;
right: 35px;
opacity: 1;
z-index: 1;
transition: all 0.5s ease 0s;
}
.box:hover:after {
top: 0;
left: 0;
bottom: 0;
right: 0;
opacity: 0;
}
/* 圖片 */
.box img {
width: 100%;
height: auto;
transform: scale(1.2);
transition: all 0.5s ease 0s;
}
.box:hover img {
transform: scale(1);
}
/* 文字內容 */
.box .box-inner-content {
position: absolute;
left: 45px;
bottom: 125px;
right: 45px;
text-align: center;
color: #fff;
opacity: 0;
transition: all 0.3s ease 0s;
}
.box:hover .box-inner-content {
opacity: 1;
bottom: 20px;
text-shadow: 0 0 10px #000;
}
/* 標題 */
.box .title {
font-size: 26px;
font-weight: bold;
margin: 0;
}
/* 文本 */
.box .post{
display: block;
font-size: 16px;
font-style: italic;
margin-bottom: 10px;
}以上就是使用CSS怎么實現一個圖片動畫特效,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。