Foros del Web » Programando para Internet » PHP »

Css dinamico con PHP

Estas en el tema de Css dinamico con PHP en el foro de PHP en Foros del Web. Hola, Me pidieron que haga una web donde el usuario pueda eleguir el Z-index para 3 capas, la cosa está en que pense hacerlo a ...
  #1 (permalink)  
Antiguo 29/05/2011, 20:03
Avatar de latinpower  
Fecha de Ingreso: septiembre-2010
Ubicación: Canelones
Mensajes: 116
Antigüedad: 13 años, 7 meses
Puntos: 10
Css dinamico con PHP

Hola,

Me pidieron que haga una web donde el usuario pueda eleguir el Z-index para 3 capas, la cosa está en que pense hacerlo a través de css, ahora, no sé cómo puedo hacer para modificar una linea especial de un texto.

Porque si lo abro común, es decir, todo el texto en una cadena de caracteres, no sé como modificar algo del medio.

¿Existe alguna funcion que, leyendo un .css o txt me devuelva el contenido de X linea, para que lo modifique y lo vuelva a introducir en el mismo lugar?

Sé que suena difícil, pero, ¿no hay una forma de hacer algo así?

Gracias!
  #2 (permalink)  
Antiguo 29/05/2011, 20:06
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 11 meses
Puntos: 1517
Respuesta: Css dinamico con PHP

Ehhh, sinceramente no entendí eso de que pueda elegir el z-index de algo. ¿Podrías específicar mejor lo que quieres hacer?
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos
  #3 (permalink)  
Antiguo 29/05/2011, 20:26
Avatar de latinpower  
Fecha de Ingreso: septiembre-2010
Ubicación: Canelones
Mensajes: 116
Antigüedad: 13 años, 7 meses
Puntos: 10
Respuesta: Css dinamico con PHP

Cita:
Iniciado por abimaelrc Ver Mensaje
Ehhh, sinceramente no entendí eso de que pueda elegir el z-index de algo. ¿Podrías específicar mejor lo que quieres hacer?
Yo le tengo que mostrar 3 capas al usuario, y el usuario tiene que elegir el valor CSS de Z-index, o sea, mediante un numero, va a elegir que capa va por encima de la otra.
  #4 (permalink)  
Antiguo 29/05/2011, 21:09
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 11 meses
Puntos: 1517
Respuesta: Css dinamico con PHP

Bueno algo así puedes hacer

index.php
Código PHP:
Ver original
  1. <?php
  2. if(!empty($_POST)){
  3.     $zIndex = (int)$_POST['z_index'];
  4.     $_SESSION[$_POST['id']] = $zIndex;
  5.     echo $zIndex;
  6.     exit;
  7. }
  8. ?>
  9. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  10. <html>
  11. <head>
  12. <link href="style.php" media="screen" rel="stylesheet" type="text/css" />
  13. <script type="text/javascript">
  14. function http(){
  15.     if(typeof window.XMLHttpRequest!='undefined'){
  16.         return new XMLHttpRequest();
  17.     }else{
  18.         try{
  19.             return new ActiveXObject('Microsoft.XMLHTTP');
  20.         }catch(e){
  21.             alert('Su navegador no soporta AJAX');
  22.             return false;
  23.         }
  24.     }
  25. }
  26.  
  27. function request(url, params, id){
  28.     var H=new http();
  29.     if(!H)return;
  30.     H.open('post',url+'?'+Math.random(),true);
  31.     H.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  32.     H.onreadystatechange=function(){
  33.         if(H.readyState==4){
  34.             document.getElementById(id).style.zIndex = H.responseText;
  35.  
  36.             H.onreadystatechange=function(){}
  37.             H.abort();
  38.             H=null;
  39.         }
  40.     }
  41.     var p='';
  42.     for(var i in params){
  43.         p+='&'+i+'='+escape(params[i]);
  44.     }
  45.     H.send(p);
  46. }
  47.  
  48. function addListener(element, type, expression, bubbling)
  49. {
  50.     bubbling = bubbling || false;
  51.  
  52.     if(window.addEventListener) { // Standard
  53.         element.addEventListener(type, expression, bubbling);
  54.         return true;
  55.     } else if(window.attachEvent) { // IE
  56.         element.attachEvent('on' + type, expression);
  57.         return true;
  58.     } else return false;
  59. }
  60.  
  61. window.onload = function(){
  62.     addListener(document.getElementById('div1'), 'click', function(){
  63.         request('<?php echo $_SERVER['PHP_SELF']; ?>',
  64.             {
  65.                 'id':'div1',
  66.                 'z_index':prompt('z-index',<?php echo array_key_exists('div1', $_SESSION) ? $_SESSION['div1'] : 1; ?>)
  67.             },
  68.             'div1'
  69.         );
  70.     });
  71.     addListener(document.getElementById('div2'), 'click', function(){
  72.         request('<?php echo $_SERVER['PHP_SELF']; ?>',
  73.             {
  74.                 'id':'div2',
  75.                 'z_index':prompt('z-index',<?php echo array_key_exists('div2', $_SESSION) ? $_SESSION['div2'] : 2; ?>)
  76.             },
  77.             'div2'
  78.         );
  79.     });
  80.     addListener(document.getElementById('div3'), 'click', function(){
  81.         request('<?php echo $_SERVER['PHP_SELF']; ?>',
  82.             {
  83.                 'id':'div3',
  84.                 'z_index':prompt('z-index',<?php echo array_key_exists('div3', $_SESSION) ? $_SESSION['div3'] : 3; ?>)
  85.             },
  86.             'div3'
  87.         );
  88.     });
  89. }
  90. </script>
  91. </head>
  92. <body>
  93. <div id="wrap">
  94.     <div id="div1"></div>
  95.     <div id="div2"></div>
  96.     <div id="div3"></div>
  97. </div>
  98. </body>
  99. </html>

style.php
Código PHP:
Ver original
  1. <?php
  2.     session_start();
  3.     header('Content-Type: text/css;');
  4. ?>
  5. *{ margin: 0; padding: 0; }
  6. html, body{ width: 100%; height: 100%; }
  7. #wrap{
  8.     position: relative;
  9.     width: 200px;
  10.     margin: 0 auto;
  11. }
  12. #div1{
  13.     width: 100px;
  14.     height: 100px;
  15.     background-color: #000;
  16.     position: absolute;
  17.     top: 1px;
  18.     left: 1px;
  19.     z-index: <?php echo array_key_exists('div1', $_SESSION) ? $_SESSION['div1'] : 1; ?>;
  20. }
  21. #div2{
  22.     width: 100px;
  23.     height: 100px;
  24.     background-color: #f00;
  25.     position: absolute;
  26.     top: 40px;
  27.     left: 30px;
  28.     z-index: <?php echo array_key_exists('div2', $_SESSION) ? $_SESSION['div2'] : 2; ?>;
  29. }
  30. #div3{
  31.     width: 100px;
  32.     height: 100px;
  33.     background-color: #00f;
  34.     position: absolute;
  35.     top: 20px;
  36.     left: 50px;
  37.     z-index: <?php echo array_key_exists('div3', $_SESSION) ? $_SESSION['div3'] : 3; ?>;
  38. }
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos

Etiquetas: css, dinamico, modificar, txt
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:13.