Ver Mensaje Individual
  #3 (permalink)  
Antiguo 10/02/2013, 10:47
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: Meter css segun resolucion y que valide en W3C

Cita:
Iniciado por Gothgauss Ver Mensaje
Buenos días

Quiero que una web se centre verticalmente si la resolución de pantalla es mayor de 1024, por lo que en el head he incluido el siguiente código:
Código HTML:
<head>

<script type="text/javascript">

if(screen.width > 1024){
document.writeln("<link href='../../css/es/1152.css' rel='stylesheet' type='text/css' media='screen' />");

}
</script>
</head> 
Pero al pasar el validador W3C me dice que hay un error:

Código:
document type does not allow element "link" here
…f='../../css/es/1152.css' rel='stylesheet' type='text/css' media='screen' />");
✉
The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).

One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error).
Que viene a decir que el código lo está metiendo en el body y no en el head.

Como haríais vosotros para que cogiera el css en función de la resolución sin usar CSS3 (porque el explorer 8 no lo soporta )
Con uno de estos doctype y usando bloques CDATA no vas a tener problemas

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <title>titulo</title>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6. <script type="text/javascript">
  7. //<![CDATA[
  8. if(screen.width > 1024){
  9. document.writeln("<link href='../../css/es/1152.css' rel='stylesheet' type='text/css' media='screen' />");
  10. }
  11. //]]>
  12. </head>
  13. </body>
  14. </html>



Código HTML:
Ver original
  1. <!DOCTYPE html>
  2. <html lang="es-ar">
  3. <meta charset="utf-8" />
  4. <title>Html5</title>
  5. <script type="text/javascript">
  6. //<![CDATA[
  7. if(screen.width > 1024){
  8. document.writeln("<link href='../../css/es/1152.css' rel='stylesheet' type='text/css' media='screen' />");
  9. }
  10. //]]>
  11. </head>
  12. </body>
  13. </html>

Si no tambien media queries, aunque para ie8 vas a necesitar algo de esto
https://www.google.com/search?btnG=1...eries+polyfill

Los comentarios condicionales de IE van a desaparecer en la versión 10 de IE, así mejor que ir dejándolos de usar

SAludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.