Solved

Overflow hidden/visible Safari problem

Posted on 2008-06-26
7
2,804 Views
Last Modified: 2013-11-19
I am using overflow:hidden to show and hide some content in a div. This works fine in IE6, IE7 and FF BUT in Safari it doesn't seem to work?

If I use inline CSS to test each state, both overflow:hidden and overflow:visible it works fine but when I try and do that dynamically with JavaScript it fails to work?

Any ideas would be great!?!

Here is my code:
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Overflow hidden</title>
 
<style type="text/css">
#special{width:900px; height:200px; background-color:#FFFFFF; border:1px dashed #999999;}
#special img{float:right; margin:10px 10px 20px; border:1px solid #666666; display:inline}
#show-all{width:900px;position:absolute;bottom:0;z-index:99;background-color: #F8F8F8;opacity: .5;filter: alpha(opacity=50);height:10px;}
#show-all2{width:900px;background-color: #CCCCCC;}
#show-all2 a{display:block; padding:2px; background-color:#0000FF; float:right;color:#FFFFFF;display:inline}
</style>
 
<script type="text/javascript">
function showhide(id){
if (document.getElementById){
obj = document.getElementById(id);
if (obj.style.overflow == "hidden"){
obj.style.overflow = "visible";
obj.style.height = "auto";
} else {
obj.style.overflow = "hidden";
obj.style.height = "200px";
}
}
}
</script>
 
</head>
 
<body>
 
<div id="special" style="overflow:hidden;">
<div id="show-all">&nbsp;</div>
<div id="show-all2"><a href="#" onclick="showhide('special'); return(false);">Show all</a><br style="clear:right" /></div>
<div style="padding:10px;">
<img src="images/service.jpg" alt="" /><br /><br />
<h1>Atom Bomb</h1>
<p>Aftermath of an atomic bomb explosion - The aftermath of an atom bomb dropped on Japan by the United States in 1945. <br />Category: Social Studies - America History<br />Film Name: The Fragile Balance<br />Key Words: atom bomb, World War II, Hiroshima, Nagasaki<br /></p>
<p>Copyrighted Material, AIMS Multimedia. </p>
<br />
</div>
<br />
<br style="clear:both" />
</div>
 
</body>
</html>

Open in new window

0
Comment
Question by:Eternal_Student
  • 4
  • 3
7 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 21882045
http://www.quirksmode.org/css/overflow.html

Safari cannot dynamically change overflow to auto or scroll. Bug solved in Safari 3.0b Windows.
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 250 total points
ID: 21882092
Here
<script type="text/javascript">
var shown=true;
function showhide(id){
var obj=document.getElementById(id);
obj.style.overflow = (shown)?"hidden":"visible";
obj.style.height   = (shown)?"200px":"auto";
shown=!shown;
}
</script>

Open in new window

0
 
LVL 18

Author Comment

by:Eternal_Student
ID: 21897576
There is no fix for Safari then?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 21897644
I just gave it to you.
The script I gave you should work on all browsers on all platforms
If you need it to save the state while navigating away and back, we need to add some code to the onLoad but otherwise it should work
Try it.
Michel
0
 
LVL 18

Author Comment

by:Eternal_Student
ID: 21899268
I just tested on IE and FF and you need to click the link a couple of times before it works. I had this problem before but im not sure how I solved it now?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 21899415
Change shown=true to shown=false
My mistake
0
 
LVL 18

Author Comment

by:Eternal_Student
ID: 21899606
Works like a treat, thank you.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question