TextMetrics.width
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
La propriété en lecture seule TextMetrics.width contient en pixels CSS la largeur d'avance du texte (la largeur de la boîte de ligne).
Syntaxe
js
readonly metrics.width;
Exemples
Étant donné cet élément <canvas>
:
html
<canvas id="canevas"></canvas>
vous pouvez obtenir un objet TextMetrics
en utilisant le code suivant :
js
var canvas = document.getElementById("canevas");
var ctx = canvas.getContext("2d");
var texte = ctx.measureText("foo"); // objet TextMetrics
texte.width; // 16;
Spécifications
Specification |
---|
HTML # dom-textmetrics-width-dev |
Compatibilité des navigateurs
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
width |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.