简体   繁体   English

CSS列表:用图像替换项目符号并添加悬停

[英]CSS List: Replacing Bullet with Image and Adding Hover

I have an unordered list that looks like the following: 我有一个看起来像下面的无序列表:

<ul>
<li><a href="test.html">Item 1<li>
<li><a href="test2.html">Item 2</li>
<li><a href="test3.html">Item 3</li>
</ul>

I want the bullet that appears to the left of each list item to be replaced by a right-facing triangle. 我希望将出现在每个列表项左侧的项目符号替换为朝右的三角形。 The triangle, along with the text beside it, should change color on hover. 三角形及其旁边的文本在悬停时应更改颜色。

CSS can produce a triangle, but it appears choppy at smaller sizes. CSS可以产生一个三角形,但在较小的尺寸下会显得不规则。 Therefore, I'm just looking for code that will allow me to edit the link location of two different triangle images. 因此,我只是在寻找允许我编辑两个不同三角形图像的链接位置的代码。

First of all, your HTML is invalid (You need to close the anchor tags). 首先,您的HTML无效(您需要关闭锚标记)。

You can change the bullet image by using the list-style-image CSS property 您可以使用list-style-image CSS属性更改项目符号图像

ul { list-style-image: url('url-of-bullet1.png'); }

and you can change it on hover the same way, but by using the hover selector so it's only applied to the item the cursor is on: 并且您可以使用相同的方式在悬停时进行更改,但是通过使用悬停选择器,使其仅应用于光标所在的项目:

ul li:hover { list-style-image: url('url-of-bullet2.png'); }

As for changing the text color, you can change it for the anchor elements by using the hover selector on the list items, like this: 至于更改文本颜色,可以通过使用列表项上的悬停选择器来更改锚元素的文本颜色,如下所示:

ul li:hover a { color: #f00; }

Here's an example 这是一个例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM