0

I have two spans. Each span has an id tag. I don't want the spans to have a class tag. I want to use css to underline the text in the span when the mouse hovers over it. What is the proper code to do this on a single line in my css file?

<span id=spanImagePreview1>Text Here <img src=url></span>
<span id=spanImagePreview2>Text Here <img src=url></span>
4

2 回答 2

2

Use a selector that matches both elements:

#spanImagePreview1:hover, #spanImagePreview2:hover { text-decoration: underline; }

Demo: http://jsfiddle.net/Guffa/9RxEb/

于 2012-09-29T10:48:55.560 回答
1

mutliple options:

if you have only these two spans: span:hover {text-decoration:underline;}

if they are descendants of a specific element #element span:hover {text-decoration:underline;}

if the spans you have have a pattern for their id try span[id*="spanImagePreview"] {text-decoration:underline;}

于 2012-09-29T10:54:18.933 回答