Ori_jpg 2022-05-18 12:08 采纳率: 100%
浏览 66
已结题

怎么用css实现鼠标移动到链接上,右边的div会切换相应的图片? 如图,鼠标移动到按钮一上时,右边的图片会变成其他图片,滑出按钮一时,图片变回去;按钮二同理

img

img


html代码


<body>
    <div class="header">
        <div class="left">
            <a href=" #">按钮一</a>
            <a href="#">按钮二</a>
            <a href="#">按钮三</a>
            <a href="#">按钮四</a>
        </div>
        <div class="right">
            <img src="images/mario.png">
        </div>
    </div>
</body>

css代码



<style>
        /* 背景 */
        body {
            width: 100%;
            height: 100%;
            background-color: #fff;
            background-image: url('images//4.jpg');
            background-repeat: no-repeat;
            background-size: cover;
        }

        a {
            color: #fff;
            text-decoration: none;
            background-color: transparent;
            display: block;
            /* 文字垂直居中 */
            line-height: 100px;
            text-align: center;
            font: 700 60px FZCuYuan-M03S;
        }

        a:hover {
            background: #fff url('images/cap.png')no-repeat;
            color: gray;
            /* 文字阴影 */
            box-shadow: 10px 10px 10px -4px rgba(0, 0, 0, .3);
            text-shadow: 5px 5px 2px rgba(0, 0, 0, .3);
        }

        .header {
            width: 900px;
            height: 200px;
            /* 盒子水平居中 */
            margin: 100px auto;
        }

        .left {
            float: left;
            width: 450px;
            height: 100px;
            /* 盒子水平居中 */
            margin: auto;
            margin-top: 200px;
        }

        .right {
            float: right;
            width: 450px;
            height: 100px;
            /* 盒子水平居中 */
            margin: auto;
            margin-top: 40px;
            background: url('images/mario.png');
            background-size: 100%;
        }

        .right img {
            width: 100%;
        }
    </style>


  • 写回答

1条回答 默认 最新

  • v逆水行舟v 2022-05-18 14:30
    关注

    你这个结构还真没办法用纯css实现出来。因为a:hover之后,想要改变的是父层兄弟节点的子节点内容,css目前不支持父选择器。
    如果能改变结构,让a能与class="right"为兄弟节点,可以通过a:hover ~ .right > img.normal 控制图片的显隐(display: none | block)。如下图:

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 6月2日
  • 已采纳回答 5月25日
  • 创建了问题 5月18日

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器