m0_71229575 2023-05-28 23:45 采纳率: 21.4%
浏览 67

html中鼠标悬停浮窗的设置


<!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>模板</title>
    <link rel="stylesheet" href="ll.css">
   
       
</head>
<body background="1.jpg"
style="background-repeat:no-repeat;
background-attachment:fixed;
background-size: 100% 100%;">
   <header>
    <h1>标题</h1>
   </header>
    


  <div class="a">
    <img src="2.jpg" alt="">
    <div class="spba">              
        <span class="jpa">景区管理</span><br>
        <a href="">景区查询和统计分析</a> 
        
      
      
    
    </div>
   </div>

  <div class="b">
    <img src="2.jpg" alt="">
    <div class="spbb">
        <span class="jpb">景点管理</span><br>
        <b href="">景点查询和统计分析</b> 
        <div class="tt"></div>
        
       
    </div>
   </div>
  

   <div class="c">
    <img src="2.jpg" alt="">
    <div class="spbc">
        <span class="jpc">评论管理</span><br>
        <c href="">评论查询和统计分析</c> 
        
    </div>
   </div>

   <div class="d">
    <img src="2.jpg" alt="">
    <div class="spbd">
        <span class="jpd">推荐管理</span><br>
        <d href="">用户的旅游需求和推荐结果</d> 
       
    </div>
   </div>

</body>
</html>


*{
  margin: 0;  
  padding: 0;
  box-sizing: border-box;
}
header{
    position: relative;/*子绝父相*/
    background: #ccc;
    text-align: center;
    height: 125px;
    background-size: 100% 100%;
 }
 header>h1{  /*子选择器*/
   
    font-size: 4vh;
    color: rgb(10, 11, 12);
    text-align: center;
    line-height:125px; /*要等于头部高度才可以使字体居中*/

}
div{
    white-space:nowrap;
}
html{
    width: 100%;
    height: 100vh;
    margin: 0 auto;
    padding: 0;

}
.a{
    width: 200px;
    height: 300px;
    background: aquamarine;
    margin-top: 100px;
    margin-left: 70px;
    line-height: 90px;
    border: 1px solid rgb(21, 21, 19);
    border-radius: 10px ;
    overflow: hidden;
    float: left;
    box-shadow: 0px 1px 3px #666;
   
}
.b{
    width: 200px;
    height: 300px;
    background: aquamarine;
    margin-top: 100px;
    margin-left: 200px;
    line-height: 90px;
    border: 1px solid rgb(21, 21, 19);
    border-radius: 10px ;
    overflow: hidden;
    float: left;
    box-shadow: 0px 1px 3px #666;
    position: relative;
}
 
.c{
    width: 200px;
    height: 300px;
    background: aquamarine;
    margin-top: 100px;
    margin-left: 200px;
    line-height: 90px;
    border: 1px solid rgb(21, 21, 19);
    border-radius: 10px ;
    overflow: hidden;
    float: left;
    box-shadow: 0px 1px 3px #666;
}
.d{
    width: 200px;
    height: 300px;
    background: aquamarine;
    margin-top: 100px;
    margin-left: 200px;
    line-height: 90px;
    border: 1px solid rgb(21, 21, 19);
    border-radius: 10px ;
    overflow: hidden;
    float: left;
    box-shadow: 0px 1px 3px #666;
}
.d img{
    width: 200px;
    height: 210px;
    float: left;
}
.c img{
    width: 200px;
    height: 210px;
    float: left;
}
.b img{
    width: 200px;
    height: 210px;
    float: left;
}


.a img{
    width: 200px;
    height: 210px;
    float: left;
}
.spbd{
    width: 200px;
    height: 90px;
    background: #fff;
    float: left;
    line-height: 30px;
    text-align: center;
}
.spbc{
    width: 200px;
    height: 90px;
    background: #fff;
    float: left;
    line-height: 30px;
    text-align: center;
}

.spba{
    width: 200px;
    height: 90px;
    background: #fff;
    float: left;
    line-height: 30px;
    text-align: center;
  
}
.spbb{
    width: 200px;
    height: 90px;
    background: #fff;
    float: left;
    line-height: 30px;
    text-align: center;
    

}

.jpa{
    color:red;
    font-weight:bold ;
    font-size: 20px;
}
.jpb{
    color:red;
    font-weight:bold ;
    font-size: 20px;
}
.jpc{
    color:red;
    font-weight:bold ;
    font-size: 20px;
}
.jpd{
    color:red;
    font-weight:bold ;
    font-size: 20px;
}
a{
    text-decoration: none;
    color: #000;

}
a:hover{
    color:red
}
b{
    text-decoration: none;
    color: #000;

}
b:hover{
    color:red
}
.tt{
    position: absolute;
    top:525px;
    left: 0;
    width: 100%;
    height: 100px;
    border-top: 1px solid #c24242;
    background-color: #871010;
    box-shadow: 0 3px 4px rgba(0,0,0,0.18);
}

请大家帮我检查一下我的代码,是这样的,我想要将鼠标移动至图中这个字段的位置悬停时,会出现一个弹窗来,然后这个弹窗内会有其他内容供我选择,就很像京东的那种

img

img


然后我跟着教程做的,可能是我的位置没有放对,一直没有达到我想要到效果,所以想请大家帮我看一下应该怎么改正,谢谢!

  • 写回答

2条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2023-05-29 08:27
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:
    <html><head><meta /><title>鼠标悬停浮窗</title><style> .hover-box{ width: 150px; height: auto; padding: 10px; background-color: #fff; box-shadow: 1px 1px 5px #ccc; position: absolute; left: 100px; / 悬浮窗左侧距离 / top: 30px; / 悬浮窗顶部距离 / display: none; / 默认不显示 / } </style></head><body>
    悬浮鼠标试试
    这里是悬浮框内容
    <script></script> </body></html>

    以上代码中,利用了CSS样式的position属性和JavaScript的事件处理函数来实现鼠标悬停浮窗。具体步骤如下:

    1. 在HTML中添加一个需要悬浮的元素,如本例中添加了一个div元素,并在鼠标移入和移出时分别触发两个JavaScript事件处理函数showHoverBox()和hideHoverBox()。

    2. 在CSS中设置悬浮框的样式,包括宽度、高度、内边距、背景颜色、阴影等属性,并将其默认设置为不显示(display: none),需要使用时再通过JavaScript将其显示。

    3. 在JavaScript中获取悬浮框的元素,并分别实现鼠标移入和移出事件的处理函数。鼠标移入时通过style.display属性将悬浮框元素显示,移出时将其隐藏。

    以上是一种简单实用的鼠标悬停浮窗的实现方法,您可以根据需要对其进行更改和优化。


    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

问题事件

  • 创建了问题 5月28日

悬赏问题

  • ¥15 券商软件上市公司信息获取问题
  • ¥100 ensp启动设备蓝屏,代码clock_watchdog_timeout
  • ¥15 Android studio AVD启动不了
  • ¥15 陆空双模式无人机怎么做
  • ¥15 想咨询点问题,与算法转换,负荷预测,数字孪生有关
  • ¥15 C#中的编译平台的区别影响
  • ¥15 软件供应链安全是跟可靠性有关还是跟安全性有关?
  • ¥15 电脑蓝屏logfilessrtsrttrail问题
  • ¥20 关于wordpress建站遇到的问题!(语言-php)(相关搜索:云服务器)
  • ¥15 【求职】怎么找到一个周围人素质都很高不会欺负他人,并且未来月薪能够达到一万以上(技术岗)的工作?希望可以收到写有具体,可靠,已经实践过了的路径的回答?