前端 五彩导航栏案例 html和css简单使用

该代码示例展示了如何使用HTML和CSS创建一组带有不同背景图片的链接按钮,点击后背景图片会改变,呈现悬浮效果。通过调整类名和设置图片URL,可以定制不同的按钮样式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

整体效果

点击前:

点击后:

1.html和css部分

<!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">
    <title>Document</title>
</head>
<style>
    a {
        display: inline-block;
        background-color: pink;
        text-decoration: none;
        text-align: center;
        line-height: 100px;
    }
    
    .nav .tong {
        background: no-repeat;
    }
    
    .nav .bg1 {
        width: 219px;
        height: 112px;
        background: url(bg1.png) no-repeat;
    }
    
    .nav .bg2 {
        width: 224px;
        height: 117px;
        background: url(bg2.png);
    }
    
    .nav .bg3 {
        width: 217px;
        height: 110px;
        background: url(bg3.png);
    }
    
    .nav .bg4 {
        width: 214px;
        height: 108px;
        background: url(bg4.png);
    }
    
    .nav .tong:hover {
        background: url(bg5.png) no-repeat;
        width: 173px;
        height: 86px;
    }
</style>

<body>
    <div class="nav">
        <a href="#" class="bg1 tong"></a>
        <a href="#" class="bg2 tong"></a>
        <a href="#" class="bg3 tong"></a>
        <a href="#" class="bg4 tong"></a>
    </div>

</body>

</html>

所需要的图片:

bg1.png

bg2.png

bg3.png

bg4.png

bg5.png

所有的分布

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值