html - 我根本无法在悬停时更改我的 div

标签 html css

我只是想将 div 颜色从浅蓝色更改为黑色。不幸的是我不能让它改变颜色或任何东西。我尝试了各种代码,但似乎都不起作用。这是我的代码。

**HTML**




    <a href="#">
    <div id="entertainment">
    <h1 style="font-size:25px;"> Entertainment </h1>
    </div>
    </a>

这是我的 CSS

    #entertainment{
     background-color:#6db1e1;
     width:160px;
     height:70px;
     margin-top:5px;
     margin-left:334px;
     position:absolute;
    }

     a,entertainment{

    color:black;
    text-decoration: none;
     }

a.entertainment:悬停{

margin-radius:20px;
background-color:green;

最佳答案

您的 a.entertainment:hover 不适用于您的 html 设置。您在该行中所说的是“我想定位一个具有类别且悬停的标签”

为了使代码与您的 html 结构一起工作,您必须从 css 选择器中删除 a 标签:

#entertainment:hover {
  /* hover style here */
}

#entertainment{
     background-color:#6db1e1;
     width:160px;
     height:70px;
     margin-top:5px;
     margin-left:334px;
     position:absolute;
}

a,entertainment{

    color:black;
    text-decoration: none;
}
     
#entertainment:hover{

    border-radius:20px;
    background-color:green;

}
    <a href="#">
    <div id="entertainment">
    <h1 style="font-size:25px;"> Entertainment </h1>
    </div>
    </a>

关于html - 我根本无法在悬停时更改我的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47583992/

相关文章:

javascript - 为 d3 网络图添加选择框

javascript - slider div的响应高度

css - 在悬停时修复 CSS Sprite

html - 使 flex 具有与最宽元素等宽的列

html - 如何让自定义对话框中的文字垂直居中

javascript - 将 CSS 样式分配给 JavaScript 中的变量

html - 使用 CSS 将一张图片 float 到另一张图片上

html - 导航栏的中心内容 - BootStrap

css - 如何创建自定义单选按钮?

javascript - 弹出窗口未在 switch 语句中打开