/    Sign up×
Community /Pin to ProfileBookmark

resizing div height according to screen size

i have a div that sits 100 pixels from the top and i want the div to be 4 pixels from the bottom of the browser. i have got some old java script that was written in the days of netscape 4 and ie 4 so it dose not work at all in firefox or the new IE. in fact it only works in safari & IE on the mac.

he is a working example of my page:
[url]http://www.thehopeandanchor.net/nypd/jstest2.htm[/url]

this is my style sheet:

[code=html]<style type=”text/css”>
<!–
div#picture_con_show_place {
position:absolute;
top: 100px;
left: 438px;
width:451px;
height:417px;
overflow: auto;
background-color:#999999;
}
–>
</style>[/code]

this is the code i use to initiate the resize:

[code=html]<body onresize=”resized()” onload=”resized()”>
[/code]

my java script:

[code=php]<script language=”JavaScript” type=”text/JavaScript”>
<!–
function resized() {

var newheight;

if (document.layers) {

//netscape not tested
newheight = window.innerHeight – 100 – 4;
document.picture_con_show_place.height = newheight+”px”;

} else if (document.all) {

//mac IE and (not PC IE)
newheight = document.body.offsetHeight – 100 – 4;
picture_con_show_place.style.height = newheight+”px”;

} else {

//works for safari – same code as for netscape
newheight = window.innerHeight – 100 – 4;
picture_con_show_place.style.height = newheight+”px”;

}

}
//–>
</script>[/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Mr_JMar 28.2005 — I am not sure if there is a 100% css way of doing it especially cross browser but someone else may come up with that.

For the time being here's one Javascript possibility


[code=php]
<HTML>
<HEAD>
<TITLE>Example</TITLE>
<script type="text/javascript" language="javascript">
<!--
function chk(){
my_div=document.getElementById("picture_con_show_place")
top_space=document.getElementById("picture_con_show_place").offsetTop
bottom_space=4
my_div.style.height=document.body.clientHeight-top_space-bottom_space

}
onresize=chk
onload=chk
//-->
</script>

<style type="text/css">
<!--
div#picture_con_show_place {
position:absolute;
top: 100px;
left: 438px;
width:451px;
height:417px;
overflow: auto;
background-color:#999999;
overflow-x:hidden
}
-->
</style>
</HEAD>
<BODY>
<div id="picture_con_show_place">
Dummy text<br><br>
Dummy text<br><br>
Dummy text<br><br>
Dummy text<br><br>
Dummy text<br><br>
Dummy text<br><br>
Dummy text<br><br>
Dummy text<br><br>
Dummy text<br><br>
Dummy text<br><br>
Dummy text<br><br>
Dummy text<br><br>
Dummy text<br><br>
Dummy text<br><br>
Dummy text<br><br>
Dummy text<br><br>
Dummy text<br><br>
Dummy text<br><br>
Dummy text<br><br>
Dummy text<br><br>
</div>
</BODY>
</HTML>
[/code]
×

Success!

Help @lomokev spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.22,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...