By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,607 Members | 2,008 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,607 IT Pros & Developers. It's quick & easy.

Body attributes...

P: n/a
Can someone tell me if there is a universal way to check the available
screen with and screen height for IE, Netscape, and Opera? Is there a
universal syntax? Thanks in advance.

Tony
Jul 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Tony Vasquez" <co**********@earthlink.net> writes:
Can someone tell me if there is a universal way to check the available
screen with and screen height for IE, Netscape, and Opera? Is there a
universal syntax? Thanks in advance.


screen.availWidth
and
screen.availHeight
Works in Netscape 4+, Mozilla, Opera 4+ (haven't tested Opera 3), amd
IE 4+. That is, probably in all current browsers.

The next questions is: What do you need it for? If it is a publically
available web page (not an intranet) then you probably don't need the
screen resolution for anything. E.g, Opera in MDI mode is completely
unaffected by the screen resolution, since all Opera page windows are
constrained by the application window. If you try to use the screen
size for anything, it will probably be unreadable.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a
Actually, I don't want the screens available width, I'm sorry, I meant the
browsers available width. What I am trying to do is center a DIV vertically
as well as horozontally. Can you help further?

Tony
"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:u1**********@hotpop.com...
"Tony Vasquez" <co**********@earthlink.net> writes:
Can someone tell me if there is a universal way to check the available
screen with and screen height for IE, Netscape, and Opera? Is there a
universal syntax? Thanks in advance.
screen.availWidth
and
screen.availHeight
Works in Netscape 4+, Mozilla, Opera 4+ (haven't tested Opera 3), amd
IE 4+. That is, probably in all current browsers.

The next questions is: What do you need it for? If it is a publically
available web page (not an intranet) then you probably don't need the
screen resolution for anything. E.g, Opera in MDI mode is completely
unaffected by the screen resolution, since all Opera page windows are
constrained by the application window. If you try to use the screen
size for anything, it will probably be unreadable.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors:

<URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html> 'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #3

P: n/a
"Tony Vasquez" <co**********@earthlink.net> writes:
Actually, I don't want the screens available width, I'm sorry, I meant the
browsers available width. What I am trying to do is center a DIV vertically
as well as horozontally. Can you help further?


The FAQ has an entry on finding the browser size:
<URL:http://jibbering.com/faq/#FAQ4_9>

I wouldn't use Javscript to center an element, though. CSS is there for
that.

You should also consider what you mean by "centering vertically". If
the document is longer than the viewport, what should the element be
centered wrt.? However, the usual use for vertical centering is to
position a div containing the entire content of the page (which I have
*never* understood. Why not use all the available space instead of
showing ones page as a stamp-sized box in the middle of an empty page).

There are several ways to center a div wrt. the page.

The most correct, according to standards, is with the following CSS:

<style type="text/css">
body,html {height:100%; /* makes document as high as the viewport */ }
div.centered {
margin:auto;
width:640px;
height:480px;
}
</style>

However, older borwsers, especially older IE's, have proplems with
auto margins. The trick that is often used in IE is more dangerous.
It positions the element with the top at the center and the uses
a negative margin to pull it up.

<!--[if IE]>
<style type="text/css">
body,html {height:100%;}
div.centered {
margin:0px;
position:absolute;
width:640px; /* positions element at 320px left of the center */
left:50%; /* */
margin-left:-320px; /* */
height:480px;
top:50%;
margin-top:-240px;
}
</style>
<[end if]-->

This method is more dangerous, because a small screen can make the
negative margin position the element above the top of the page (or to
the lef tof the left side). You cannot scroll there, so the content is
lost.

I recommend against vertical centering in these cases.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4

P: n/a
How about using a single-celled table?

[table width="100% height="100%" border="0"]
[tr]
[td align="center" valign="middle"]CONTENT HERE[/td]
[/tr]
[/table]

Tony Vasquez wrote:
Actually, I don't want the screens available width, I'm sorry, I meant the
browsers available width. What I am trying to do is center a DIV vertically
as well as horozontally. Can you help further?

Tony


Jul 20 '05 #5

P: n/a
Lewis Shadoff wrote:
How about using a single-celled table?

[table width="100% height="100%" border="0"]
[tr]
[td align="center" valign="middle"]CONTENT HERE[/td]
[/tr]
[/table]
Misuse of tables. A table is a table is a table. [tm]
Do not use it for layout.
[Top post]


Don't do that, either.
PointedEars
Jul 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.