个人资料卡片
本课属于 Coddy HTML 学习旅程的“前端实践”单元。第 32 课,共 35 课。
挑战
简单你需要处理一个关于著名飞行员 Amelia Earhart 的完整 HTML 页面。页面已经包含结构和内容,但还需要添加 CSS 样式,让它在手机和大屏幕上都显示美观。
你的任务是添加缺少的 CSS 样式,完成设计。
- 定义 CSS 变量,分别表示主色、文字颜色和背景色。将它们应用到卡片的背景、文字、标题和按钮上。
- 设置大屏幕布局(
min-width: 768px):- 让图片显示在左侧,文字显示在右侧(使用
flex-direction: row)。 - 为图片和内容设置合适的宽度。
- 让图片显示在左侧,文字显示在右侧(使用
- 在大屏幕上,为图片应用
object-fit: cover;,使其缩放效果更自然。
亲手试试
<!DOCTYPE html>
<html>
<head>
<title>Explorer Profile Card</title>
<style>
/* Variables */
body {
font-family: Arial, sans-serif;
background-color: #f4f4f9;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.card {
background-color: #fff;
border-radius: 12px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
overflow: hidden;
max-width: 600px;
display: flex;
flex-direction: column;
}
.card img {
width: 100%;
height: auto;
}
.card-content {
padding: 20px;
color: #000;
}
.card-content h2 {
margin-top: 0;
color: #555;
}
.card-content p {
line-height: 1.5;
margin-bottom: 20px;
}
.card-content button {
background-color:#555;
color: white;
border: none;
padding: 10px 20px;
border-radius: 6px;
cursor: pointer;
transition: background 0.3s ease;
}
.card-content button:hover {
background-color: #1b4f72;
}
/* Larger screens → side by side */
</style>
</head>
<body>
<div class="card">
<img src="https://upload.wikimedia.org/wikipedia/commons/b/b2/Amelia_Earhart_standing_under_nose_of_her_Lockheed_Model_10-E_Electra%2C_small.jpg" alt="Amelia Earhart">
<div class="card-content">
<h2>Amelia Earhart</h2>
<p>Amelia Earhart was a pioneering American aviator who became the first woman to fly solo across the Atlantic Ocean. She inspired generations with her courage and adventurous spirit.</p>
<button>Read More</button>
</div>
</div>
</body>
</html>
前端实践中的所有课
自己练习: Web 在线编辑器