tags:

views:

398

answers:

4

i have the following div in my website:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<title></title>
    <style type="text/css">
        .popup
        {
            float: left;
            position: fixed;
            top: 50%;
            left: 50%;
            margin-left: -332px;
            margin-top: -260px;
            width: 665px;
            height: 550px;
            border: solid 1px blue;
            z-index: 100;
        }
    </style>
</head>
<body>
    <div class="popup" >content content content...</div>
    body body body.....
    <br />

</html>

and this css

.popup
{
    float:left;  
    position: fixed;
    top: 50%;
    left: 50%;
    margin-left: -332px;
    margin-top: -260px;
    width: 665px;
    height:550px;
    z-index:100;
}

I have a problem that the div is not fully shown when screen resoultion is lower than 1024x768 (ie 800x600). the top and bottom part of the popup is clipped.

Im looking for a css code or js to detect client with resoultion lower than 600(height) and will resize the div height and add scrollbars. for all other customers i want to keep the div height 550px;

A: 

Following javascript code may help you to get the screen's width & height:

window.screen.width
window.screen.height
Sachin Gaur
A: 

You would be better off detecting browser window client area rather than screen resolution.

function getWindowClientArea(){
  if( !isNaN(parseInt(window.innerWidth,10))) { //Non-IE
    return { width: window.innerWidth, height: window.innerHeight };
  } else if( document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode'
    return { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight };
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible
    return { width: document.body.clientWidth, height: document.body.clientHeight };
  }
}
Graza
+1  A: 

Have a look at this

r3zn1k
A: 

I think the best way is to do this with JavaScript.

But if you absolutely want to write it with CSS, you can use @media specific CSS rules.

Try this :

<style type="text/css">
        .popup
        {
            float: left;
            position: fixed;
            top: 50%;
            left: 50%;
            margin-left: -332px;
            margin-top: -260px;
            width: 665px;
            height: 550px;
            border: solid 1px blue;
            z-index: 100;
        }

        @media all and (max-device-height: 1023px){
            .popup {
                height: 450px;
                overflow: scroll;
            }
        }
</style>
Daan