Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/05/2013, 23:05
Avatar de berkeleyPunk
berkeleyPunk
 
Fecha de Ingreso: febrero-2013
Ubicación: México :C
Mensajes: 565
Antigüedad: 11 años, 2 meses
Puntos: 22
Pregunta ¿cómo hacer efecto trasparencia al fondo no al texto de un div?

Recuerdo haber visto en algún lado un menú desplegable, que al abrirse dejaba ver el fondo, con un opacity de .3, quizá. El efecto hover consistía en que el ítem semi-transparente se volvía un poco más opaco, con un opacity de .7, talvez. Pero el texto de los ítems del menú nunca era transparente, sino sólido. ¿Cómo hacer eso?

La cosa no es tan fácil como poner un opacity al elemento, pues la opacidad aplica a todo el elemento, lo cual incluye el texto adentro. ¿Cómo hay que proceder para que el texto quede sólido, sin opacidad?

Veamos el siguiente ejemplo:

Código HTML:
Ver original
  1. <div class="capaTransparente">
  2.   Texto dentro de un DIV trasparente
  3. </div>
  4.  
  5. <div class="capaFondo">
  6.     Qu. Whether a people can be called poor, where the common sort are well fed, clothed, and lodged?
  7.     Qu. Whether the drift and aim of every wise State should not be, to encourage industry in its members?
  8.     Qu. Whether the four elements, and man's labor therein, be not the true source of wealth?
  9.     Qu. Whether money be not only so far useful, as it stirred up industry, enabling men mutually to participate the fruits of each other's labor?
  10.     Qu. Whether any other means, equally conducing to excite and circulate the industry of mankind, may not be as useful as money.
  11. </div>

Le aplicamos el siguiente estilo:
Código CSS:
Ver original
  1. .capaFondo {
  2.       position:relative;
  3.       top:0px;
  4.       left:0px;
  5.       width:500px;
  6.       height:300px;
  7.       background-color:blue;}
  8. .capaTransparente {
  9.       position:absolute;
  10.       top:50px;
  11.       left:50px;
  12.       width:300px;
  13.       height:200px;
  14.       background-color:gray;
  15.       color:black;
  16.       font-size:40px;
  17.       z-index:1;
  18.       opacity:.3;}
  19.  
  20. .capaTransparente:hover {opacity:.7;}

Última edición por berkeleyPunk; 19/05/2013 a las 23:12