「青训营 X 码上掘金」主题创作活动之我的名片

121 阅读4分钟

当青训营遇上码上掘金

前言

本文为 「青训营 X 码上掘金」主题创作活动入营版 的征选文章,详细内容参考如下:

「青训营 X 码上掘金」主题创作活动入营版 开启!

题目介绍

本文选择主题:我的名片

名片是向人介绍自我的重要工具,作为一名程序员用代码做自我介绍是一件非常酷炫的事情。请大家围绕“我的名片”这个主题进行代码创作。

效果图

效果图.webp

文件结构

首先,在我们的项目文件夹中,我们需要一个HTML文件,一个CSS文件和一个用于存储配置文件图像的文件夹。如下图所示

image.png

创作过程

HTML

首先,我们必须建立基本的html结构。让我们将以下代码放入index.html文件中。

<!DOCTYPE html>  
<html lang="en">  
<head>  
<meta charset="UTF-8">  
<meta http-equiv="X-UA-Compatible" content="IE=edge">  
<meta name="viewport" content="width=device-width, initial-scale=1.0">  
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>  
<link rel="stylesheet" href="style.css">  
<title>Awesome Profile Card</title>  
</head>  
<body>  
<div class="card">  
<div class="card-header">  
<img src="img/profile-image-placeholder.jpg" alt="Profile Image" class="profile-img">  
</div>  
<div class="card-body">  
<p class="name">Your Name</p>  
<a href="#" class="mail">yourname@amail.com</a>  
<p class="job">Developer | Designer</p>  
</div>  
  
  
<div class="social-links">  
<a href="#" class="fab fa-github social-icon"></a>  
<a href="#" class="fab fa-twitter social-icon"></a>  
<a href="#" class="fab fa-youtube social-icon"></a>  
<a href="#" class="fab fa-linkedin social-icon"></a>  
</div>  
  
  
<div class="card-footer">  
<p class="count"><span>120k</span> Followers | <span>10k</span> Following</p>  
</div>  
</div>  
</body>  
</html>

我们需要将添加style.cssindex.html。此外,我们还需要采用font-awesome链接社交图标。

接下来,我们需要为卡片添加CSS样式。从现在开始,我们将使用该style.css文件。

CSS

首先,我们将添加一些基本样式,这些样式将应用于所有地方。

* {  
margin: 0;  
padding: 0;  
box-sizing: border-box;  
text-decoration: none;  
transition: 0.3s;  
}  
  
  
body {  
font-family: "Montserrat";  
background-color: #b8b6b6;  
color: #fdfdfd;  
}

没有CSS,卡将如下所示。

1.png

如果我们想把它变成漂亮一点的卡片,现在,我们需要为卡片添加背景颜色,字体大小,位置等样式属性。

.card {  
max-width: 250px;  
margin: 150px auto 0;  
background-color: #42515a;  
box-shadow: 0 10px 90px #00000024;  
text-align: center;  
font-size: 20px;  
border-radius: 15px;  
}  
  
  
.card .card-header {  
position: relative;  
height: 48px;  
}

个人资料图片

然后,我们将样式添加到个人资料图像。还有一些简单的悬停效果。

.card .card-header .profile-img {  
width: 130px;  
height: 130px;  
border-radius: 1000px;  
position: absolute;  
left: 50%;  
transform: translate(-50%, -50%);  
border: 8px solid #c74385;  
box-shadow: 0 0 20px #00000033;  
}  
  
  
.card .card-header .profile-img:hover {  
width: 180px;  
height: 180px;  
border: 8px solid #d885af;  
}

现在,我们应该看到卡中的一些重大更改。它正在变成很酷的东西。

2.png

卡体设计

该card-body内容包含姓名,电子邮件和专业。我们将为每个样式添加不同的样式。当然还有一些悬停效果。

.card .card-body {  
padding: 10px 40px;  
}  
  
  
.card .card-body .name {  
margin-top: 30px;  
font-size: 22px;  
font-weight: bold;  
color: #c74385;  
}  
  
  
.card .card-body .name:hover {  
margin-top: 30px;  
font-size: 24px;  
color: #d885af;  
}  
  
  
.card .card-body .mail {  
font-size: 14px;  
color: #c2bdbd;  
}  
  
  
.card .card-body .mail:hover {  
font-size: 16px;  
color: #ffffff;  
}  
  
  
.card .card-body .job {  
margin-top: 10px;  
font-size: 14px;  
}

更改后,卡片样式如下图所示。

3.png

添加社交链接信息

现在,我们为卡片添加自定义社交链接。我们已经font-awesome在HTML中使用了图标。我们将使用CSS修改一下图标样式,让其变得更漂亮。

.card .social-links {  
display: flex;  
justify-content: center;  
align-items: center;  
margin-top: 30px;  
}  
  
  
.card .social-links .social-icon {  
display: inline-flex;  
align-items: center;  
justify-content: center;  
height: 40px;  
width: 40px;  
background-color: #c74385;  
color: #ffffff;  
font-size: 20px;  
border-radius: 100%;  
text-decoration: none;  
margin: 0 13px 30px 0;  
}  
  
  
.card .social-links .social-icon:last-child {  
margin-right: 0;  
}  
  
  
.card .social-links .social-icon:hover {  
background-color: #d885af;  
height: 50px;  
width: 50px;  
text-decoration: none;  
}

查看图标的外观。

4.png

到这里,我们的卡片样式就快完成了。

最后,我们将在脚注中添加一些简单的CSS,就基本实现我们想要的效果了。

添加页脚样式

我们将对card-footer进行一些小的更改。

.card .card-footer {  
background-color: #c74385;  
border-bottom-left-radius: 15px;  
border-bottom-right-radius: 15px;  
padding: 20px 0 20px 0;  
}  
.card .card-footer .count {  
font-size: 14px;  
}

修改完之后,我们得到了期望的卡片外观效果。

5.png

我们将通过一些媒体查询来完成我们的设计。

@media screen and (max-width: 575px) {  
.card {  
width: 96%;  
}  
  
.card .card-body {  
padding: 10px 20px;  
}  
}

在网站上使用此卡时,我们将根据自己需要,更改媒体查询。也许我们需要像这样的多张卡片。然后,我们将在网格系统中使用它们。这些卡在大,中,小屏幕上的外观如何,我们需要根据最终需求,进行样式的调整修改即可。