473,387 Members | 3,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

IE not handling background on empty anchors.

r0g
1
It seems w3 don't want us applying widths to our inline elements, I can't see why not and indeed if you throw in the 'position: absolute' property (without any 'top' 'bottom' etc) Firefox, Opera & to some extent IE let you. This is ideal for making graphical links. Sadly though, when you apply a background colour (or image) underneath such a link IE gets literal about the 'absolute'ness of position and won't let these elements move/flow even when other blocks are hidden/unhidden with 'display: none/block'.

For all I know IE might be doing this right, indeed as inline widths are not kosher there may be no right / wrong way of dealing with this however... That still leaves me with a problem - if it can't be solved this way, is there another similarly concise way of solving it?

Thanks for your help :-)

Roger.

Code follows...
[HTML]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">
/*.results {background-color: #0f0;} if this is uncommented it breaks in IE */
.mltd {vertical-align: top;}
.lst_details{display: none;}
.ml{background-image: url(http://www.technicalbloke.com/more_less.png);
background-position: 0px 0px;
background-repeat: no-repeat;
position: absolute;
width: 35px; height: 14px;}
</style>
<script type="text/javascript">
function flip(id, img, offset)
{ var item = document.getElementById(id);
var g = document.getElementById(img);
if(item.style.display == 'block')
{ item.style.display = 'none';
g.style.backgroundPosition = '0px 0px'; }
else
{ item.style.display = 'block';
g.style.backgroundPosition = offset+' 0px'; } }
</script>
</head>
<body>
<div class="results">
Item One<span><a class="ml" id="mb_1" onClick="javascript:flip('lst_1', 'mb_1', '-35px')">&nbsp;</a></span><br>
<div class="lst_details" id="lst_1">&nbsp;Details for item one.</div>
Item Two <a class="ml" id="mb_2" onClick="javascript:flip('lst_2', 'mb_2', '-35px')">&nbsp;</a><br>
<div class="lst_details" id="lst_2">&nbsp;Details for item two.</div>
Item Three <a class="ml" id="mb_3" onClick="javascript:flip('lst_3', 'mb_3', '-35px')">&nbsp;</a><br>
<div class="lst_details" id="lst_3">&nbsp;Details for item three.</div>
</div>
</body>
</html>
[/HTML]
Jan 6 '08 #1
2 1838
drhowarddrfine
7,435 Expert 4TB
The definition of 'inline' is that content is in an 'inline box', such as text. I fyou don't want part of it to be inline, then use a span, as you do, and say 'display:block'. Then you can move it around without having to use abs pos.
Jan 6 '08 #2
garrow
32
Position absolute takes an element out of the normal document flow and places it in an 'absolute' location. Funnily enough.

Setting its parent element to
[HTML]position:relative; [/HTML]
will allow the box to be absolutely placed within the parent element.
like so;

[HTML] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">
/*.results {background-color: #0f0;} if this is uncommented it breaks in IE */
.mltd {vertical-align: top;}
.lst_details{display: none;}
.ml{background-image: url(http://www.technicalbloke.com/more_less.png);
background-position: 0px 0px;
background-repeat: no-repeat;
position: absolute;
width: 35px; height: 14px;
}
.linkparent { position:relative;}
</style>
<script type="text/javascript">
function flip(id, img, offset)
{ var item = document.getElementById(id);
var g = document.getElementById(img);
if(item.style.display == 'block')
{ item.style.display = 'none';
g.style.backgroundPosition = '0px 0px'; }
else
{ item.style.display = 'block';
g.style.backgroundPosition = offset+' 0px'; } }
</script>
</head>
<body>
<div class="results">
Item One<span class="linkparent"><a class="ml" id="mb_1" onClick="javascript:flip('lst_1', 'mb_1', '-35px')">&nbsp;</a></span><br>
<div class="lst_details" id="lst_1">&nbsp;Details for item one.</div>
Item Two <a class="ml" id="mb_2" onClick="javascript:flip('lst_2', 'mb_2', '-35px')">&nbsp;</a><br>
<div class="lst_details" id="lst_2">&nbsp;Details for item two.</div>
Item Three <a class="ml" id="mb_3" onClick="javascript:flip('lst_3', 'mb_3', '-35px')">&nbsp;</a><br>
<div class="lst_details" id="lst_3">&nbsp;Details for item three.</div>
</div>
</body>
</html>[/HTML]


That being said, I can think of a number of ways of doing this better, using
a) semantic markup
b) progressive enhancement (ie not relying on javascript)
c) valid CSS

Heres a starting point.
[HTML] <style type="text/css" media="screen">
dl,
dl dd,
dl dt { margin:0; padding:0;}
dd { display:none; }
</style>

<div>
<dl>
<dt>Item One</dt>
<dd id="details_1">Details for item one.</dd>
<dt>Item Two</dt>
<dd id="details_2">Details for item two.</dd>
<dt>Item Three</dt>
<dd id="details_3">Details for item three.</dd>
</dl>

</div>[/HTML]
Jan 7 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Brian Roberts | last post by:
I'm using using generators and iterators more and more intead of passing lists around, and prefer them. However, I'm not clear on the best way to detect an empty generator (one that will return no...
13
by: Mikko Ohtamaa | last post by:
From XML specification: The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag. (This means that <foo></foo> is equal to...
2
by: mlv2312 | last post by:
Hi, I have experienced problems when dealing with nested anchors. I implemented some code to perform highlighting and specific anchors are used for the searched words. The problem is when the...
1
by: mlv2312 | last post by:
Hi, I have experienced problems when dealing with nested anchors. I implemented some code to perform highlighting and specific anchors are used for the searched words. The problem is when the...
5
by: proximus | last post by:
Hi, I am trying to change the background of table TD's. The problem is that I have no access to the HTML code. SO I am trying to alter this using Javascript/DOM in an external .js file. I...
3
by: Mike Barnard | last post by:
Hi all, newbie here. Odd sounding subject but I can't describe it any better. I'm trying to teach myself a little about CSS. In a test site (not published) I am trying to use CSS to make...
1
by: eomer | last post by:
I have a lengthy page with several paragraphs. At the top of the page is a navigation bar with anchors to each of the paragraphs (the links). The problem is this: If I go to the page (after the...
2
by: Wing Siu | last post by:
Dear All I would like to ask you an opinion of ASP.NET exception handling I am working in a software house and need to deliver a system to our customer. However, as we knew (of course it can...
16
by: Lastwebpage | last post by:
Hello, I am little surprised about the following: <a href="#" ... I found some lines about the href tag for a site should point to an name or in XHTML to an ID, but in both cases this seems to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.