CSS学习碎碎念之卡片展示

效果展示:

代码展示

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片展示</title>
</head>

<body>
    <div class="menu-container">
        <div class="col-sm-3 menu-card" onclick="window.open('${site.url}', '_blank')">
            <img src="25.jpg">
            <div class="menu-content">
                <h2>标题</h2>
                <p>描述</p>
            </div>
        </div>
        <div class="col-sm-3 menu-card" onclick="window.open('${site.url}', '_blank')">
            <img src="25.jpg">
            <div class="menu-content">
                <h2>标题</h2>
                <p>描述</p>
            </div>
        </div>
        <div class="col-sm-3 menu-card" onclick="window.open('${site.url}', '_blank')">
            <img src="25.jpg">
            <div class="menu-content">
                <h2>标题</h2>
                <p>描述</p>
            </div>
        </div>
    </div>
   
</body>

</html>

<style>
    .menu-card {
        /* 鼠标放到卡片上去后会出现小手 */
        cursor: pointer;
        /* 设置开票宽度 */
        width: 300px;
        /* 设置卡片高度 */
        height: 130px;
        /* 设置卡片外边框直接的距离 */
        margin: 20px;
        /* 设置背景色 */
        background-color: #fff;
        /* 设置圆角 */
        border-radius: 10px;
        /* 设置边框阴影 */
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
        /* 超出之后覆盖 */
        overflow: hidden;
        /* 移动效果 设置时间 */
        transition: transform 0.3s;
        /* 布局方式自适应 */
        display: flex;
        /* 中间放置 */
        align-items: center;
    }

    .menu-container {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 20px;
        /* 内边框 */
        padding: 20px;
    }

    .menu-card:hover {
        /* 设置悬停效果为向上移动 */
        transform: translateY(-5px);
    }

    .menu-card img {
        width: 80px;
        height: 80px;
        margin-left: 10px;
        object-fit: cover;
        border-radius: 10px;
    }

    .menu-content {
        padding: 20px;
    }

    .menu-content h2 {
        font-size: 16px;
        margin-left: 10px;
        margin-bottom: 10px;
        color: #e27d60;
    }

    .menu-content p {
        font-size: 14px;
        margin-left: 10px;
        color: #7f7f7f;
        margin-bottom: 20px;
    }

    .menu-content div a {
        display: inline-block;
        padding: 8px 16px;
        background-color: #e27d60;
        color: #fff;
        text-decoration: none;
        border-radius: 4px;
        transition: background-color 0.3s;
    }

    .menu-content a:hover {
        background-color: #bf6043;
    }
</style>

碎碎念

  • cursor: pointer; 可以把鼠标变为小手
  • width: 300px; 设置容器的宽度
  • height: 130px; 设置容器的高度
  • margin: 20px; 设置相邻容器之间的距离(外边框距离),margin可以单独对上下左右进行设置。如margin-left margin-right ...
  • padding: 20px; 设置内边框距离
  • background-color: #fff; 设置背景色
  • border-radius: 10px; 设置边框圆角
  • box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1); 设置边框阴影部分
  • overflow: hidden; 超出部分被隐藏
  • transition: transform 0.3s; 设置移动时间
  • transform: translateY(-5px); 设置移动距离
  • display: flex; 设置布局类型
  • align-items: center; 中间防止
  • justify-content: center; 内容放在中间
    类的选择 还可以通过.menu-content div a方式按照层级选择标签
    div标签提供容器功能,一般标签之间以纵向排列,如果需要横排需要改变display布局方式
相关推荐
崇山峻岭之间1 分钟前
Matlab学习记录30
开发语言·学习·matlab
朔北之忘 Clancy16 分钟前
2020 年 6 月青少年软编等考 C 语言一级真题解析
c语言·开发语言·c++·学习·算法·青少年编程·题解
菩提小狗24 分钟前
Sqli-Labs Less-3 靶场完整解题流程解析-豆包生成
前端·css·less
saoys1 小时前
Opencv 学习笔记:一文掌握四种经典图像滤波(均值 / 高斯 / 中值 / 双边)
笔记·opencv·学习
●VON1 小时前
可信 AI 认证:从技术承诺到制度信任
人工智能·学习·安全·制造·von
一瞬祈望2 小时前
⭐ 深度学习入门体系(第 11 篇): 卷积神经网络的卷积核是如何学习到特征的?
深度学习·学习·cnn
wdfk_prog2 小时前
[Linux]学习笔记系列 -- 底层CPU与体系结构宏
linux·笔记·学习
GISer_Jing2 小时前
AI Agent:学习与适应、模型上下文协议
人工智能·学习·设计模式·aigc
im_AMBER2 小时前
Leetcode 100 在链表中插入最大公约数
数据结构·c++·笔记·学习·算法·leetcode·链表
时间黑客2 小时前
SolidWorks百日建模(二)
学习