Movatterモバイル変換


[0]ホーム

URL:


  1. Tecnologia Web para desenvolvedores
  2. JavaScript
  3. Referência JavaScript
  4. Objetos Globais
  5. String
  6. String.prototype.fontsize()

Esta página foi traduzida do inglês pela comunidade.Saiba mais e junte-se à comunidade MDN Web Docs.

View in EnglishAlways switch to English

String.prototype.fontsize()

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see thecompatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

O métodofontsize() cria um elemento HTML<font> que faz com que uma string seja exibida no tamanho da fonte especificada.

Nota:O elemento<font> foi removido doHTML5 e não deve mais ser usado. Em vez disso, web developers devem usar apropriedade CSS correspondente.

Sintaxe

str.fontsize(size)

Parâmetros

size

Um número inteiro entre 1 e 7.

Valor retornado

Uma string contendo um elemento HTML<font>.

Descrição

Ao especificar o tamanho como um inteiro, você define o tamanho da fonte do texto para um dos 7 tamanhos definidos. Ao especificarsize como uma string como "-2", você ajusta o tamanho da fonte do texto em relação ao tamanho definido na tag<basefont>.

Exemplos

Usandofontsize()

O exemplo a seguir usa métodos do objeto global String para alterar o tamanho de uma string:

js
var worldString = "Olá, mundo";console.log(worldString.small()); // <small>Olá, mundo</small>console.log(worldString.big()); // <big>Olá, mundo</big>console.log(worldString.fontsize(7)); // <font size="7">Olá, mundo</fontsize>

Com o objetoelement.style você pode obter o atributostyle do elemento e manipulá-lo de forma mais genérica, por exemplo:

js
document.getElementById("#oIdDoElemento").style.fontSize = "0.7em";

Especificações

Specification
ECMAScript® 2026 Language Specification
# sec-string.prototype.fontsize

Compatibilidade com navegadores

Veja também

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp