How can I know the width of the screen where the web page is opening?

0

I am doing some initial tests already in the production state. All the pages of the project load the following at the beginning:

<style>
  body {
    padding-left: 30px;
    padding-right: 30px;
  }
</style>

I was testing a mobile device and it looks good on a perfect PC. Now, when I upload data entry forms (registration form for example) I do the following:

<div style="padding-left: 20%; padding-right: 20%">
      ... dentro de este div, todo el formulario de ingreso de datos
</div>

On the desk, it looks perfect, it gives a sense of interesting prolixity but when I see it on the mobile device, it looks too narrow.
I would like to detect the size of the screen and in those cases use another div in which I have neither padding-left nor padding-right.
QUESTION 1: This how would I have to do it?
QUESTION 2: Could I do it with PHP?

    
asked by MNibor 13.08.2017 в 23:49
source

1 answer

0

I found this PHP code that works wonders !!!

<?php
if(!isset($_GET['Ancho']) && !isset($_GET['Alto'])){
    echo "<script language=\"JavaScript\">
    <!-- 
    document.location=\"$PHP_SELF?Ancho=\"+screen.width+\"&Alto=\"+screen.height;
    //-->
    </script>";
} else {
    if(isset($_GET['Ancho']) && isset($_GET['Alto'])) {
        // Resolución de pantalla detectada
        echo "Esta es tu resolucion de pantalla: Ancho= ".$_GET['Ancho']." y Alto= ".$_GET['Alto'];
    } else {
        // error en la detección de resolución de pantalla
        echo "No se ha podido detectar la resolución de pantalla";
    }
}
?>
    
answered by 14.08.2017 / 00:17
source