473,473 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

background colours gone in dropmenu items

Below dropmenu and javascript modifies ul properties depending on if a link
within matches the current url.

If a match is found the .high style applies to the relevant section, or .low
if no match is found.

This works only for static list, or in the case of a dropmenu, with the
first visible link of each UL only, as tested on Konqueror and Mozilla.

When "position: absolute" is used in conjuction with removing the items from
the page the background-color is gone as they are brought back with the
"left: auto" for some reason, although not other values such as font-size.

Does anyone know why and how to keep the background-color value?

<style type="text/css">
..high {background-color: #99FFCC; font-size: 80%;}
..low {background-color: #33CC00; font-size: 80%;}

..head, .head ul, .low ul {
padding: 0;
margin: 0;
list-style: none;
}

#menu a {
display: block;
width: 10em;
}

..head, .low {
float: left;
width: 10em;
}

..head li ul, .low li ul {
position: absolute;
width: 10em;
left: -999em;
}

..head li:hover ul, low li:hover {
left: auto;
}

</style>
<script type="text/javascript">

function doClass(){
var As, ff, x;
var a = RegExp('.*/'); // Needed many times, compile for speed
var f = document.URL.replace(a,''); // filename of current page
var d = document.getElementById('menu');
var uls = d.getElementsByTagName('ul');

for (var i=0, j=uls.length; i<j; i++){
x = uls[i];

// If the UL className string includes word 'head'
if ( /\bhead\b/.test(x.className) ){
/* note: add forward slashes around "\bhead\b" if removed by newsreader */

// Get its A elements
As = x.getElementsByTagName('a');

// Search for matching file names
for (var k=0, m=As.length; k<m; k++) {
ff = As[k].href.replace(a,'');

// If match, modify the className string of the parent UL
if ( ff == f ){
x.className = x.className.replace(/\blow\b/,'high');

// No need to continue once we've found one
return;
}
}
}
}
}
</script>
</head>

<body onload="doClass();">

<div id="menu">

<ul class="head low">
<li><a href="z0.html">Flora&nbsp;&amp;&nbsp;funa</a>

<ul class="sub">
<li><a href="z1.html">Pretty&nbsp;flowers</a></li>
<li><a href="z2.html">Deadly&nbsp;vines</a></li>
</ul>

</li>
</ul>

<ul class="head low">
<li><a href="z3.html">Aquatic&nbsp;creatures</a>
<ul class="sub">
<li><a href="z4.html">Pretty&nbsp;fish</a></li>
<li><a href="z5.html">Don&#39t&nbsp;eat</a></li>
</ul>
</li>
</ul>

</div>

<div style="clear:left">

"To vacillate or not to vacillate, that is the question ... or is it?"

</div>

Jul 21 '05 #1
1 1635
michael wrote:

Below dropmenu and javascript modifies ul properties depending on if a link
within matches the current url.


This isn't a CSS issue, but one of the DOM or JavaScript in general. Try
asking in ng comp.lang.javascript.

--
Reply email address is a bottomless spam bucket.
Please reply to the group so everyone can share.
Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alistair Birch | last post by:
Hi I want rows of a table to appear in alternating background colours. Having looked around the web I can't find any solution apart from waiting for the next version of CSS, so I tried building...
7
by: Thomas Wieser | last post by:
Hi, my problem: I have some tables with transparent backgrounds, which are changed in colours within a JavaScript DOM function to have a roll-over effect. Now, i can't get them back...
5
by: navavil | last post by:
Hi I used some css class in my web page for graphic design (with url), now when I am sending the page to printer all the background images are gone )-: ? 10x
4
by: david.graham18 | last post by:
Hi I spotted some nice code to change the background colour of a web page to one of four different colours at random but I can't find it now! The method was to select a number at random from 1...
3
by: Peter Williams | last post by:
Hi All, I want to write some javascript for a html page which does the following. Imagine that the page contains a table with 2 columns and 3 rows, e.g.: +---+---+ | A | B | +---+---+
6
by: Nancy Carter | last post by:
I'm trying to set the background color of a frameset to black. The following code doesn't work in either IE 6.0 or Firefox. Any ideas why? <frameset bgcolor="#000000" frameborder="0" border="0"...
4
by: Lachlan Hunt | last post by:
Hi, I'm looking for an interoperable method of determining the current background colour of an element that is set using an external stylesheet. I've tried: elmt.style.backgroundColor; but...
11
by: shapper | last post by:
Hello, I am trying to create a header with a background color and a padding of the text. I know that if I apply the background color to the header it will expand 100%. So I did the following:...
2
by: patrick.waldo | last post by:
Hi all, I am trying to figure out a way to read colors with xlrd, but I did not understand the formatting.py module. Basically, I want to sort rows that are red or green. My initial attempt...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.