Forum Moderators: not2easy

Message Too Old, No Replies

bug with Firefox

firefox leaves space while using collapsable elms

         

blackeagle2

2:05 am on Feb 19, 2006 (gmt 0)

10+ Year Member



Hi,

I have a script that shows and hides DIVs, in fact there is a list of titles and content that is shown or hidden.

I had to use the style "clear: left;" on each div.

But now when I collapse elements it leaves the space it created. it only removes this unnecessary space when expanding the next element....

IE handles this correctly for once ...

Any idea or trick?

Mokita

2:41 am on Feb 19, 2006 (gmt 0)

10+ Year Member



There is a nice show/hide script here, that works well in both IE and FF and degrades well. Perhaps you could use that or examine the code to see how they did it:

[tjkdesign.com...]

drhowarddrfine

3:48 am on Feb 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am not aware of any such bug in Firefox. The fact that you say it works in IE but not Firefox leads me to believe there is a coding problem. But without the complete code, it's not possible to offer a solution.

bedlam

4:30 am on Feb 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Any idea or trick?

Well, I think I might have a fairly good idea--your description corresponds closely to what would happen if you'd used "visibility:hidden;" but were expecting the behaviour of "display:none;"

Visibility: [w3.org]

The 'visibility' property specifies whether the boxes generated by an element are rendered. Invisible boxes still affect layout (set the 'display' property to 'none' to suppress box generation altogether)
(emphasis added)

Display: [w3.org]

none

This value causes an element to generate no boxes in the formatting structure (i.e., the element has no effect on layout).

(emphasis added)

-b

blackeagle2

1:45 pm on Feb 19, 2006 (gmt 0)

10+ Year Member



bedlam > no I used display : none ... and clear: left;

I will try tjkdesign toggle solution, if not working, I will give my complete source code.

Thanks 4 helping

blackeagle2

12:21 am on Feb 20, 2006 (gmt 0)

10+ Year Member



It would need a lot of time to re-code it to use TJK toggle's script.

Here is the source, unfortunately it's not complete ( complete code is way larger ), but it contains code that is needed to show/hide elements.

see examplified full code in next post

[edited by: SuzyUK at 2:22 pm (utc) on Feb. 20, 2006]
[edit reason] examplified code but in next post [/edit]

blackeagle2

12:29 pm on Feb 20, 2006 (gmt 0)

10+ Year Member



here is a code with the working javascript

<html>
<head>
<title>Test</title>
<link rel="stylesheet" type="text/css" href="msn.css" media="screen">
<style type="text/css" media="screen">
#container
{
width : 450px;
background-color: #FFFFFF;
border : 1px solid #999999;
/* MSN messenger style */
padding : 0 7px 5px 5px;
}

.content
{
width : 100%;
text-align : left;
background-color : #C9E3A1;
/* MSN Messenger style */
background-color : #F4B800;
border : 1px solid #808080;
/*background-color : #800000;*/
}

.content p
{
margin : 0px;
}

.white
{
background-color : #FFFFFF;
}

.titre
{
color: #000000;
background : url('../../_img/interface/right_menu_arrow.gif') 8px 8px no-repeat;
padding : 0px 0px 0px 20px;
vertical-align: super;
cursor : pointer;
clear : both;
}

.titre a
{
cursor : pointer;
}

.topRight, .rssSelect
{
float: right;
margin : 2px;
}
</style>

</head>
<body>
<div align="center">
<div id="container">

<div style="display: block;" class="content" id="news">
<div style="clear: left;" class="news_solvay">
<span class="titre"><a>SENS: Les éleveurs européens inquiets</a></span>
<div style="display: none;" id="news0">
<img src="_19_flu_EPA.jpg" align="left" hspace="4" vspace="4" width="120">Lorem ipsum.<a href="s_e_LCn_s/page_5763_411059.shtml">lire l'article</a></div>
</div>
<div style="clear: left;" class="news_solvay">
<span class="titre"><a>ECONOMIE: Arcelor vise l'Inde</a></span>
<div style="display: none;" id="news1">
<img src="_19_arcelor_PYT.jpg" align="left" hspace="4" vspace="4" width="120">Lorem ipsum.<a href="economie/page_5720_411091.shtml">lire l'article</a></div></div>
<div style="clear: left;" class="news_solvay">
<span class="titre"><a>CULTURE: Toujours plus de lecteurs à la Foire</a></span>
<div style="display: none;" id="news2">
<img src="_19_Foire_RM.jpg" align="left" hspace="4" vspace="4" width="120">lorem ipsum<a href="culture/page_5730_411081.shtml">lire l'article</a></div></div>
<div style="clear: left;" class="news_solvay">
<span class="titre"><a>TENNIS: La vraie victoire d'Amélie</a></span>
<div style="display: none;" id="news3">
<img src="_19_AMetKIM_EPA.jpg" align="left" hspace="4" vspace="4" width="120">Lorem ipsum.<a href="page_5944_411074.shtml">lire l'article</a></div></div>
<div style="clear: left;" class="news_solvay">
<span class="titre"><a>JO_HIVER_2006: Walter Mayer licencié</a></span>
<div style="display: none;" id="news4">
<img src="_19_mayer_AFP.jpg" align="left" hspace="4" vspace="4" width="120">lorem ipsum.<a href="page_6126_411061.shtml">lire l'article</a></div></div>
</p>
</div>
</div>
<script type="text/javascript">
function afficheDescription()
{
displayNextElm(this,1); return false;
}

function getSiblingElm(elm, drn)
{
elm = elm.parentNode;
var strSibling = drn==-1? "previousSibling":"nextSibling";
while( (elm=elm[strSibling]) && elm.nodeType!= 1){}
return elm¦¦null;
}

function displayNextElm(elm,boolShow)
{
elm = getSiblingElm(elm);
if(elm)
{
if(elm.style.display == "none")
{
elm.style.display = "block";
}
else
{
elm.style.display = "none";
}
}
}

function makeClickable()
{
var zDT = document.getElementById('news').getElementsByTagName('a')
for(var i=0;i<zDT.length;i++)
{
zA = zDT[i];
if(zA.href.length == 0) zA.onclick = afficheDescription;
}
}
makeClickable();
</script>
</body></html>

** ¦¦ - remember to change these back to unbroken pipes **

[edited by: SuzyUK at 2:19 pm (utc) on Feb. 20, 2006]
[edit reason] examplified and summarised code [/edit]

drhowarddrfine

2:05 pm on Feb 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You will never get IE to display the same as modern browsers such as Firefox without a proper doctype. I recommend html4 strict.

SuzyUK

2:24 pm on Feb 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



blackeagle2, When I tried it using a paste of the code, it looked the same in both FF and IE?

That it is not "reserving" the space?

Suzy

blackeagle2

7:32 pm on Feb 20, 2006 (gmt 0)

10+ Year Member



actually you have to click on a title to get a description and an image, it seems the image overflows the div space. When you click on the same title it hides the description but leaves a space that is difference between the div size and image size.