Cómo aplicar la fuente global a todo el documento HTML


Tengo una página HTML que incluye algo de texto y formato. Quiero que tenga la misma familia de fuentes y el mismo tamaño de texto ignorando todo el formato interno del texto.

Quiero establecer un formato de fuente global para la página HTML.

¿Cómo puedo lograr esto?

Author: venkatvb, 2011-08-11

6 answers

Debería poder utilizar los elementos asterisk y !important dentro de CSS.

html *
{
   font-size: 1em !important;
   color: #000 !important;
   font-family: Arial !important;
}

El asterisco coincide con todo (probablemente podrías escaparte sin el html también).

El !important asegura que nada puede anular lo que ha establecido en este estilo (a menos que también sea importante). (esto es para ayudar con su requisito de que debe "ignorar el formato interno del texto", lo que entendí que significa que otros estilos no pueden sobrescribir estos)

El resto de la el estilo dentro de los tirantes es como cualquier otro estilo y puedes hacer lo que quieras allí. Elegí cambiar el tamaño de la fuente, el color y la familia como ejemplo.

 202
Author: Amadiere,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-08-11 12:31:57

Creo que la mejor práctica es establecer la fuente en el cuerpo:

body {
    font: normal 10px Verdana, Arial, sans-serif;
}

Y si decides cambiarlo por algún elemento podría ser fácilmente sobreescrito:

h2, h3 {
    font-size: 14px;
}
 29
Author: Teneff,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-08-11 12:25:17

Establézcalo en el selector de cuerpo de su css. Por ejemplo,

body {
    font: 16px Arial, sans-serif;
}
 13
Author: Petecoop,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-08-17 09:56:48

Utilice el siguiente css:

* {
    font: Verdana, Arial, 'sans-serif' !important;/* <-- fonts */
}

El selector * significa cualquier/todos los elementos, pero obviamente estará en la parte inferior de la cadena alimentaria cuando se trata de anular más selectores específicos.

Tenga en cuenta que la bandera !important-hará que el estilo font-para * sea absoluto, incluso si se han utilizado otros selectores para establecer el texto (por ejemplo, el body o tal vez un p).

 9
Author: ninetwozero,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-08-11 12:30:10

Nunca debe usar * + !important. ¿Qué pasa si desea cambiar la fuente en algunas partes de su documento HTML? Siempre debe usar el cuerpo sin importante. Utilice !important solo si no hay otra opción.

 4
Author: Rakowu,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-08-17 09:39:54

Prueba esto:

body
{
    font-family:your font;
    font-size:your value;
    font-weight:your value;
}
 -1
Author: anglimasS,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-08-11 12:26:42