webForumDet fria alternativet

Ändra bakgrundsfärg vid onmouseover?

HTML & CSS

7 svar · 346 visningar · startad av SimOnline

Medlem sedan juli 20031 132 inlägg
Frågan#1

Hur ändrar man bakgrundsfärg vid onmouseover? Det funkar ju bara på table/tr/td vad jag har erfarit. Hur gör man med div/span/li etc?

Medlem sedan dec. 20042 245 inlägg
#2
div:hover {background-color: red;}
span:hover {background-color: green;}
li:hover {background-color: yellow;}

Synd bara att IE inte har tillräckligt stöd för CSS.

Medlem sedan juli 20013 378 inlägg
#3

Re: Ändra bakgrundsfärg vid onmouseover?

SimOnline skrev:

Hur gör man med div/span/li etc?

Hmm...
Det här verkar fungera i "de stora"...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Ett exempel</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
</head>

<body>
<div>
<span style="background-color:yellow;"
 onmouseover="this.style.backgroundColor='black';this.style.color='white'"
 onmouseout="this.style.backgroundColor='yellow';this.style.color=''">
Sample span element with mouse event handlers.
</span>

<div style="background-color:yellow;"
 onmouseover="this.style.backgroundColor='black';this.style.color='white'"
 onmouseout="this.style.backgroundColor='yellow';this.style.color=''">
Sample div element with mouse event handlers.
</div>

<ul>
<li style="background-color:yellow;"
 onmouseover="this.style.backgroundColor='black';this.style.color='white'"
 onmouseout="this.style.backgroundColor='yellow';this.style.color=''">
Sample element with mouse event handlers.
</li>
</ul>
</div>
</body>
</html>

Testa: http://member.webforum.nu/2241/rollovertest.html

Vilka webbläsare är det du har problem med att få bakgrundsfärgbyten att fungera i ?

Medlem sedan okt. 20001 285 inlägg
#4

kan också ange bara class namn t.ex

 onmouseover="this.className='tabhover'" onmouseout="this.className='tabplain'"
Medlem sedan juli 20041 081 inlägg
#5

Hur ser koden ut när det ska vara i en tabell?

Medlem sedan juli 20013 378 inlägg
#6

Hmm...

Så här kanske ;)

<table style="background-color:red;"
 onmouseover="this.style.backgroundColor='black';this.style.color='red'"
 onmouseout="this.style.backgroundColor='red';this.style.color=''"
 border="1"
 cellspacing="10">
<tr>
<td>Tabellcell utan rollover </td>
<td style="background-color:yellow;"
 onmouseover="this.style.backgroundColor='black';this.style.color='white'"
 onmouseout="this.style.backgroundColor='yellow';this.style.color=''">
Tabellcell med egen rollover
</td>
</tr>
<tr style="background-color:teal;"
 onmouseover="this.style.backgroundColor='black';this.style.color='white'"
 onmouseout="this.style.backgroundColor='teal';this.style.color=''">
<td>Rollover på raden</td>
<td>Rollover på raden</td>
</tr>
</table>

//red: lade till lite större exempel :birp

Medlem sedan juli 20041 081 inlägg
#7

Okej

Medlem sedan dec. 20042 245 inlägg
#8

Typ: (snip)

262 ms totalt · 4 externa anrop · v20260731065814-full.a51de22e
122 ms — deklarationer (db)
0 ms — hämta statistik (cache)
135 ms — hämta tråd, inlägg och bilagor (db)
123 ms — ändringar (db)