HTML+CSS排行榜实现代码,复制粘贴可使用

在这里插入图片描述

如何用HTML和CSS创建一个具有吸引力的创作者排行榜

在数字化时代,排行榜是吸引用户注意的绝佳方式。无论是展示最受欢迎的产品、文章还是创作者,一个设计精良的排行榜都能提升用户的参与度和兴趣。本文将指导你如何使用HTML和CSS创建一个具有吸引力的创作者排行榜,包括为前三名添加鲜艳的颜色和圆形头像框。

1. HTML结构

首先,我们需要创建基本的HTML结构。这包括一个包含排行榜标题和列表的容器。

<div class="ranking-container">
    <h2 class="ranking-title">创作者排行</h2>
    <ul class="ranking-list">
        <!-- 排行榜列表项 -->
    </ul>
</div>
2. CSS样式

接下来,我们使用CSS来美化这个排行榜。这包括设置背景颜色、边框半径、阴影效果以及字体样式。

body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f4;
    margin: 0;
    padding: 20px;
}

.ranking-container {
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    max-width: 400px;
    margin: auto;
}

.ranking-title {
    text-align: center;
    font-size: 24px;
    color: #333;
}

.ranking-list {
    list-style: none;
    padding: 0;
}

.ranking-list li {
    border-bottom: 1px solid #eee;
    padding: 10px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ranking-list li:last-child {
    border-bottom: none;
}

.ranking-position {
    color: #666;
    font-size: 22px;
    font-weight: bold;
}

.ranking-name {
    font-size: 18px;
    color: #333;
}

.ranking-value {
    font-size: 16px;
    color: #555;
}
3. 添加头像和颜色

为了使排行榜更具吸引力,我们将为每个列表项添加圆形头像,并为前三名添加鲜艳的颜色。

.avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    overflow: hidden;
    margin-right: 10px;
}

.top-three {
    color: #ff6700; /* 鲜艳的颜色 */
}

HTML中,我们将头像图片插入到每个列表项中:

<li>
    <span class="ranking-position top-three">1</span>
    <div class="avatar"><img src="头像图片URL" alt="头像 1"></div>
    <span class="ranking-name">游山记</span>
    <span class="ranking-value">100万能力值</span>
</li>
4. 完整的HTML页面

将所有内容放在一起,我们得到一个完整的HTML页面:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>创作者排行</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>

    <div class="ranking-container">
        <h2 class="ranking-title">创作者排行</h2>
        <ul class="ranking-list">
            <li>
                <span class="ranking-position top-three">1</span>
                <div class="avatar"><img src="https://example.com/avatar1.png" alt="头像 1"></div>
                <span class="ranking-name">游山记</span>
                <span class="ranking-value">100万能力值</span>
            </li>
            <!-- 其他列表项 -->
        </ul>
    </div>

</body>
</html>

通过这种方式,你可以创建一个既美观又功能性强的创作者排行榜,为用户提供清晰的视觉体验。

好的,以下是使用HTMLCSS和JavaScript实现贪吃蛇游戏的代码HTML: ``` <!DOCTYPE html> <html> <head> <title>Snake Game</title> <style> body { margin:0; padding:0; } #canvas { background-color: #ddd; display: block; margin: 0 auto; } </style> </head> <body> <canvas id="canvas"></canvas> <script src="snake.js"></script> </body> </html> ``` CSS: ``` #canvas { width: 400px; height: 400px; border: 1px solid #000; } ``` JavaScript: ``` // 获取 canvas 元素和绘图上下文 var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); // 定义贪吃蛇和食物的初始位置和大小 var snake = [{ x: 10, y: 10 }, { x: 9, y: 10 }, { x: 8, y: 10 }]; var food = { x: Math.floor(Math.random() * 20), y: Math.floor(Math.random() * 20) }; var direction = "right"; // 初始方向为右 // 画布格子的大小 var gridSize = 20; // 定义画布中所有元素的颜色 var snakeColor = "#000"; var foodColor = "#f00"; var bgColor = "#ddd"; // 定义函数用来绘制一个方格 function drawGrid(x, y, color) { ctx.fillStyle = color; ctx.fillRect(x * gridSize, y * gridSize, gridSize, gridSize); } // 定义函数用来绘制整个画布 function draw() { // 清空画布 ctx.fillStyle = bgColor; ctx.fillRect(0, 0, canvas.width, canvas.height); // 绘制贪吃蛇 snake.forEach(function (segment) { drawGrid(segment.x, segment.y, snakeColor); }); // 绘制食物 drawGrid(food.x, food.y, foodColor); } // 定义函数用来更新贪吃蛇的位置 function update() { // 根据当前的方向计算新的蛇头位置 var head = { x: snake[0].x, y: snake[0].y }; if (direction === "right") head.x += 1; if (direction === "left") head.x -= 1; if (direction === "up") head.y -= 1; if (direction === "down") head.y += 1; // 将新的蛇头加入到贪吃蛇的数组中 snake.unshift(head); // 如果蛇头与食物的位置相同,就吃掉食物并重新生成一个新的食物 if (head.x === food.x && head.y === food.y) { food = { x: Math.floor(Math.random() * 20), y: Math.floor(Math.random() * 20) }; } else { // 否则,移除贪吃蛇的尾部 snake.pop(); } } // 定义函数用来处理按键事件 function handleKeyDown(event) { if (event.keyCode === 37 && direction !== "right") direction = "left"; if (event.keyCode === 38 && direction !== "down") direction = "up"; if (event.keyCode === 39 && direction !== "left") direction = "right"; if (event.keyCode === 40 && direction !== "up") direction = "down"; } // 注册按键事件的监听器 document.addEventListener("keydown", handleKeyDown); // 定时调用 update 和 draw 函数,实现动画效果 setInterval(function () { update(); draw(); }, 100); ``` 你可以将以上代码复制粘贴到三个文件中:一个是HTML文件,一个是CSS文件,一个是JavaScript文件。将这三个文件放在同一个目录下,然后在浏览器中打开HTML文件,就可以运行贪吃蛇游戏了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值