当青训营遇上码上掘金
前言
当青训营遇上码上掘金
名片是向人介绍自我的重要工具,作为一名程序员用代码做自我介绍是一件非常酷炫的事情。
对于前端程序员来说,使用代码制作一张名片最直观地介绍自己给别人的方式就是通过使用 HTML、CSS、JS 绘制一个Web网页,向人展示自己,下面就使用伪类和CSS来制作一个简单的带动态特效和图标的个人名片。
实现
- 创建一个外部容器用来封装名片内部各个元素,一个内部容器存放需要实现动态特效的内容区。
<div class="container">
<div class="content"></div>
<ul>
<li></li>
</ul>
</div>
- 填入主要内容:image部分是外层表面图片, info为部分个人信息展示, ul列表则是图标及其链接。
<div class="container">
<div class="image">
<img src="https://avatars.githubusercontent.com/u/84793349?v=4">
</div>
<div class="content">
<div class="info">
<h2>
XTU - ZhuBa</h2>
<span>Web Developer <a href="https://www.zhuba.cloud/">zhuba.cloud</a></span>
<p>yanwenjunxtu@gmail.com 18175744945</p>
</div>
</div>
<ul>
<li><a href="https://github.com/zhuba-Ahhh" target="_blank"><span class="fab fa-github"></span></a></li>
<li><a href="https://www.zhuba.cloud/img/QQ.jpg"><span class="fab fa-qq"></span></a></li>
<li><a href="https://www.zhuba.cloud/img/WX.jpg"><span class="fab fa-weixin"></span></a></li>
</ul>
</div>
- 基础样式,加上基础样式, grid布局使得名片位于画面中心,动态特效则使用了CSS的transform、transition translateY属性实现过渡效果和opacity用来隐藏多余元素,使得实现效果更加好看。
* {
margin: 0;
padding: 0;
font-family: 'Poppins', sans-serif;
}
html,
body {
display: grid;
height: 100%;
place-items: center;
text-align: center;
background: #f2f2f2;
}
.container {
position: relative;
height: 500px;
width: 400px;
overflow: hidden;
background: #fff;
box-shadow: 0px 1px 5px 0px rgba(0, 0, 0, 0.3);
transition: 0.3s ease-out;
}
.container .image {
background: #000;
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
z-index: 2;
transition: transform 0.3s ease-out;
}
.image img {
height: 100%;
width: 100%;
object-fit: cover;
transition: opacity 0.3s ease-out;
}
.container ul {
display: flex;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 3;
list-style: none;
}
ul li {
margin: 0 5px;
}
ul li a {
display: block;
height: 50px;
width: 50px;
color: #000;
line-height: 50px;
font-size: 20px;
border-radius: 50%;
opacity: 0;
transform: translateY(200px);
background: #fff;
transition: transform 0.3s ease-out, opacity 0.3s ease-out;
}
.container .content {
position: relative;
width: 100%;
height: 100%;
background: #fff;
}
.info {
position: absolute;
bottom: 12px;
text-align: center;
width: 100%;
color: #000;
line-height: 26px;
}
.info h2 {
font-size: 27px;
margin: 3px 0;
}
.info span {
color: #1a1a1a;
}
a {
text-decoration: none;
}
- 样式变换,主要是利用伪类来控制元素的大小变换,此处主要是hover。
.container:hover {
box-shadow: 0px 1px 35px 0px rgba(0, 0, 0, 0.3);
}
.container:hover .image {
transform: translateY(-100px);
}
.container:hover .image img {
opacity: 0.7;
}
.container:hover .image {
transform: translateY(-100px);
}
.container:hover>ul>li>a {
opacity: 1;
transform: translateY(0);
}
.container:hover>ul>li:nth-child(2) a {
transition-delay: 0.1s;
}
.container:hover>ul>li:nth-child(3) a {
transition-delay: 0.2s;
}
.container:hover>ul>li:nth-child(4) a {
transition-delay: 0.3s;
}
.container:hover>ul>li:nth-child(5) a {
transition-delay: 0.4s;
}
- 图标特效,此处使用了 facebook 图标库,直接使用CDN或者js的资源,然后,选择自己需要的图标类使用即可,如下,并且可以添加相关链接。
<li>
<a href="https://github.com/zhuba-Ahhh" target="_blank">
<span class="fab fa-github">
</span>
</a>
</li>
<li>
<a href="https://www.zhuba.cloud/img/QQ.jpg">
<span class="fab fa-qq">
</span>
</a>
</li>
<li>
<a href="https://www.zhuba.cloud/img/WX.jpg">
<span class="fab fa-weixin">
</span>
</a>
</li>
完整代码
效果如下,谢谢观看。