Hallo,
Ich versteh es trotzdem nicht, sorry. Kenn mich nicht soooo gut aus.
Kannst du mir vllt so ein Beispiel machen?
mit z.B. bild1.htm, bild2.htm usw.
Ich dachte du möchtest bei jedem Aufruf ein anderes (Hintergrund-)Bild haben und nicht bei jeder Seite?
Eine XHTML Seite mit dem Namen test.html:
<!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" lang="de-de" xml:lang="de-de">
<head>
<title>Zufallsheader Test</title>
<link rel="stylesheet" href="/css/screen.css" type="text/css" media="screen, projection" />
</head>
<body>
<div id="head"></div>
<script type="text/javascript">
[code lang=javascript]( function () {
var c = ['a','b','c','d','e','f','g','h','i','j','k'];
document.getElementById('head').className = c[Math.round(Math.random()*c.length)];
}
) ()
> </script>
> </body>
> </html>[/code]
>
>
> Eine CSS-Seite mit dem Namen screen.css im gleichen Verzeichnis:
> ~~~css
>
> #head {
> background: url(default.jpg) top left no-repeat white;
> width: 500px;
> height: 200px;
> }
> /* Hier kommen die einzelnen verschiedenen Bilder (Klassen) */
> #head.a { background-image: url(1.jpg); }
> #head.b { background-image: url(2.jpg); }
> #head.c { background-image: url(3.jpg); }
Die Bilder müssen im gleichen Verzeichnis sein wie die CSS Datei, damit sie so gefunden werden.
So wird bei jedem Aufruf der Seite in der JavaScript Funktion erst einmal eine Zufallszahl generiert. Diese Zahl wird dann zum hinzufügen der CSS-Klasse zum <div id="head"> element benutzt. Wenn die Klasse hinzugefügt wurde, wird das CSS dieser Klasse auf das Div angewendet. In der externen CSS-Datei werden die Klassen definiert, so dass jede Klasse ein anderes Hintergrundbild bekommt.
Grüße
Jeena Paradies
Zu früh gefreut. Irgentwas mach ich immer falsch.
- http://home.arcor.de/aktuelleinfo/
Wie fügt man des dort ein, ohne das Bild oben zu zerstören.
(bei mir kommt dann immer ein schwarzes Bild)
index.htm:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN">
<html>
<head>
<title>euRO Chaos - Aktuelle Liste</title>
<link rel="stylesheet" href="format.css" type="text/css">
</head>
<body><br />
<table align="center" bgcolor="#000000" cellspacing="0" cellpadding="0" border="0" width="680" height="240">
<td width="100%">
<table cellspacing="1" cellpadding="0" border="0" width="100%">
<!--Logo-->
<td align="center" class="logo" >
<table align="center" cellspacing="0" cellpadding="0" border="1" width="680" height="240" style="border:solid 0px #000000;">
</table>
</tr>
<!--Logo Ende-->
<td align="center" width="100%" class="leiste">
<table bgcolor="#93B9DB" width="100%" border="0" cellpadding="0" cellspacing="0">
<td>
<table id="menu2" width="100%" border="0" cellpadding="0" cellspacing="1">
<td > Links</a></td>
<td ><a href="http://www.euro-ro.net/" onfocus="this.blur()">euRo Homepage</a></td>
<td ><a href="http://rocheck.de/" onfocus="this.blur()">Pricewatch</a></td>
<td > <img class="point1" src="images/pixelspace.gif" width="6" height="6" border="0" alt=""> <img class="point2" src="images/pixelspace.gif" width="6" height="6" border="0" alt=""> <img class="point3" src="images/pixelspace.gif" width="6" height="6" border="0" alt=""> Info</a></td>
<td ><a href="buy.html" onfocus="this.blur()">Kaufe [Buy]</a></td>
<td ><a href="sell.html" onfocus="this.blur()">Verkaufe [Sell]</a></td>
</table></td>
</table></td>
<tr>
<td valign="top" bgcolor="#ffffff" width="100%" height="284" class="inhalt" >
<!--Text-->
<!--Text Ende-->
<tr>
<td align="center" class="leisteun" valign="top" >· © 2006 ·</td>
</body>
</html>
format.css:
/* schriftstil,abstände */
body
{margin-top: 10px; margin-left: 0px; margin-right: 0px;margin-bottom: 10px; color: #000000;
background-color:#eaf1f7; font: normal 12px/18px times, serif;}
table,tr,td
{color: #000000;font: normal 12px/18px verdana, times, serif;}
/* scrolleiste internet explorer ab vers.5.5 */
body
{scrollbar-arrow-color: #AABECA; scrollbar-base-color: #ffffff;
scrollbar-highlight-color : #000000; scrollbar-shadow-color : #ffffff;
SCROLLBAR-TRACK-COLOR: #bfd6e6;}
/* grundlayout*/
.inhalt
{background-color:#ffffff;}
.leisteun
{background-color:#689bc0;color:white; font-size: 10px; height:20px; line-height:20px;}
.logo
{color:black; height:160px; background: #ffffff url("images/Alberta.jpg"); background-position: 100% 0%;}
.banner
{-moz-opacity: 0.66; _filter: progid:DXImageTransform.Microsoft.Alpha(opacity=66);
border:solid 1px #000000; background-color:#689bc0;}
.hpname
{color:#ffffff; font-weight:normal; letter-spacing:2px;}
ul
{list-style-type:square;}
.point1 {border:solid 1px black;background-color:#7095dc}
.point2 {border:solid 1px black;background-color:#CCDAF2}
.point3 {border:solid 1px black;background-color:#ffffff}
/* menue oben */
#menu2 a , #menu2 a:visited , #menu2 a:active
{display:block; color:#ffffff; background: url("images/Menü.gif"); text-decoration:none ;
font: normal 11px verdana, times, serif; line-height:24px; text-decoration:none ;
padding: 0px 0px 0px 0px; text-align:center; width:110px;}
#menu2 a:hover
{color:#000000; text-decoration:none ; background: url("images/Menü2.gif");}
/* allgemeine links im text */
a:link, a:visited, a:active
{font: normal 12px/18px verdana, times, serif;text-decoration:underline;color:#000000}
a:hover
{font: normal 12px/18px verdana, times, serif;text-decoration:none;background-color:#689bc0;color:#ffffff;}