---
title: "Ändra bakgrundsfärg vid onmouseover?"
type: "forum-thread"
url: "https://www.webforum.nu/amne/html-css/119041-ändra-bakgrundsfärg-vid-onmouseover"
topic: "HTML & CSS"
topic_url: "https://www.webforum.nu/amne/html-css"
author: "SimOnline"
published: "2004-12-31T20:34:58.000Z"
updated: "2005-01-01T16:35:08.000Z"
replies: 7
views: 366
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/html-css/119041-ändra-bakgrundsfärg-vid-onmouseover"
---

# Ändra bakgrundsfärg vid onmouseover?

## #1 — SimOnline, 2004-12-31T20:34Z

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?

Permalänk: https://www.webforum.nu/p/119041

## #2 — zcorpan, 2005-01-01T00:59Z

```
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.

Permalänk: https://www.webforum.nu/p/1516756

## #3 — jarvklo, 2005-01-01T10:52Z

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 ?

Permalänk: https://www.webforum.nu/p/1516842

## #4 — Fuel, 2005-01-01T11:53Z

kan också ange bara class namn t.ex

```php
 onmouseover="this.className='tabhover'" onmouseout="this.className='tabplain'"
```

Permalänk: https://www.webforum.nu/p/1516866

## #5 — ade, 2005-01-01T12:49Z

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

Permalänk: https://www.webforum.nu/p/1516879

## #6 — jarvklo, 2005-01-01T13:01Z

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

Permalänk: https://www.webforum.nu/p/1516887

## #7 — ade, 2005-01-01T14:22Z

Okej

Permalänk: https://www.webforum.nu/p/1516940

## #8 — zcorpan, 2005-01-01T16:35Z

Typ: (snip)

Permalänk: https://www.webforum.nu/p/1516997

---

Tråden på webben: https://www.webforum.nu/amne/html-css/119041-ändra-bakgrundsfärg-vid-onmouseover
