- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经为 HTML/CSS 网站边栏编写了代码,我想确保当用户将鼠标悬停在边栏中的某个元素上时,其背景会突出显示。
它只显示我的正常列表,悬停功能不起作用。有什么问题?
body {
margin: 0;
}
.sidebar {
float: right;
background-color: #F4ECFC;
/* Sidebar Background */
width: 200px;
/* Width of side bar */
height: 900px;
padding-top: 0px;
/* Padding above the header */
font-family: helvetica;
/* Font for the sidebar */
}
.sidebar a {
text-decoration: none;
/* Removes the underline from links. */
color: #0B0036;
/* Text color of the menu items */
}
.sidebar ul {
line-height: 40px;
overflow: hidden;
margin-left: 0;
padding-left: 0;
}
.sidebar ul li .listItemA {
/* list-style-type: none; */
background-color: #F4ECFC;
/* Background colour of the menu items. */
}
.sidebar ul li .listItemA a:hover {
background-color: purple;
}
.listItemA {
text-align: center;
}
<div class="sidebar">
<ul>
<li class="listItemA"><a href="#">Class1</a></li>
<li class="listItemA"><a href="#">Class2</a></li>
<li class="listItemA"><a href="#">Class3</a></li>
<li class="listItemA"><a href="#">Class4</a></li>
<li class="listItemA"><a href="#">Class5</a></li>
</ul>
</div>
最佳答案
您首先要做的一件事是给您的链接 display: block;
,这使它们占据 100% 的可用宽度。
然后像这样简化链接和相对悬停的样式:
.sidebar ul .listItemA {
/* list-style-type: none; */
background-color: #F4ECFC;
/* Background colour of the menu items. */
}
.sidebar ul .listItemA:hover a {
background-color: purple;
}
正如在对您的问题的评论中所指出的,您在 li
和 .listItemA
之间有一个空格,我只是删除了 li
以实现正确的选择器,但您也可以将选择器的那部分更改为 li.listItemA
。
这里真正重要的变化是在列表项悬停时设置链接样式:
.sidebar ul .listItemA:hover a { ... }
这会告诉浏览器在悬停列表项时更改链接的背景。
body {
margin: 0;
}
.sidebar {
float: right;
background-color: #F4ECFC;
/* Sidebar Background */
width: 200px;
/* Width of side bar */
height: 900px;
padding-top: 0px;
/* Padding above the header */
font-family: helvetica;
/* Font for the sidebar */
}
.sidebar a {
display: block;
text-decoration: none;
/* Removes the underline from links. */
color: #0B0036;
/* Text color of the menu items */
}
.sidebar ul {
line-height: 40px;
overflow: hidden;
margin-left: 0;
padding-left: 0;
}
.sidebar ul .listItemA {
/* list-style-type: none; */
background-color: #F4ECFC;
/* Background colour of the menu items. */
}
.sidebar ul .listItemA:hover a {
background-color: purple;
}
.listItemA {
text-align: center;
}
<div class="sidebar">
<ul>
<li class="listItemA"><a href="#">Class1</a></li>
<li class="listItemA"><a href="#">Class2</a></li>
<li class="listItemA"><a href="#">Class3</a></li>
<li class="listItemA"><a href="#">Class4</a></li>
<li class="listItemA"><a href="#">Class5</a></li>
</ul>
</div>
关于html - 悬停功能在 CSS 侧栏中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56400105/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!