Was heißt "die" Schriftgröße?
body{font-size: 110%;}
body{font-size: 2.5em;}
body{font-size: 110%;}
body{font-size: 2.5em;}
body{font-size: 10.0pt;}
body{font-size: 10.0px;}
ob im CSS irgendwo eine bestimmte Einheit für die Schriftgröße verwendet
var units = Array.from(new Set(Array.from(document.styleSheets)
.map(function(sheet) { return Array.from(sheet.cssRules) })
.reduce(function(arr,x) { return arr.concat(x, []) })
.filter(function(e) { return e.style })
.map(function(e) { return e.style.getPropertyValue('font-size') })
.filter(function(fs) { return fs !== '' })
.filter(function(fs) { return /^\d+[^0-9]+$/.test(fs) })
.map(function(fs) { return fs.match(/[^0-9]+$/) })
.reduce(function(arr, x) { return arr.concat(x, []) })))
vHTML = document.getElementsByTagName("*");
var units = Array.from(new Set(Array.from(document.getElementsByTagName("*"))
.map(function(e) { return e.style.getPropertyValue('font-size') })
.filter(function(fs) { return /^\d+[^0-9]+$/.test(fs) })
.map(function(fs) { return fs.match(/[^0-9]+$/)[0] })))
var units = Array.from(new Set(Array.from(document.getElementsByTagName("*"))
.map(e => e.style.getPropertyValue('font-size'))
.filter(fs => /^\d+[^0-9]+$/.test(fs))
.map(fs => fs.match(/[^0-9]+$/)[0])))
var units = Array.from(new Set(Array.from(document.getElementsByTagName("*"))
.map(function(e) { return e.style.getPropertyValue('font-size') })
.filter(function(fs) { return /^\d+[^0-9]+$/.test(fs) })
.map(function(fs) { return fs.match(/[^0-9]+$/)[0] })))
console.log(units)
Was kann ich nun mit diesem Ergebnis machen, damit ich die fontsize auslesen kann?
- 0: "%"
- length: 1
- __proto__: Array(0)
- length: 0
- constructor: ƒ Array()
- concat: ƒ concat()
- copyWithin: ƒ copyWithin()
- fill: ƒ fill()
- find: ƒ find()
- findIndex: ƒ findIndex()
- lastIndexOf: ƒ lastIndexOf()
- pop: ƒ pop()
- push: ƒ push()
- reverse: ƒ reverse()
- shift: ƒ shift()
- unshift: ƒ unshift()
- slice: ƒ slice()
- sort: ƒ sort()
- splice: ƒ splice()
- includes: ƒ includes()
- indexOf: ƒ indexOf()
- join: ƒ join()
- keys: ƒ keys()
- entries: ƒ entries()
- values: ƒ values()
- forEach: ƒ forEach()
- filter: ƒ filter()
- flat: ƒ flat()
- flatMap: ƒ flatMap()
- map: ƒ map()
- every: ƒ every()
- some: ƒ some()
- reduce: ƒ reduce()
- reduceRight: ƒ reduceRight()
- toLocaleString: ƒ toLocaleString()
- toString: ƒ toString()
- Symbol(Symbol.iterator): ƒ values()
- Symbol(Symbol.unscopables): {copyWithin: true, entries: true, fill: true, find: true, findIndex: true, …}
- __proto__: Object
Die kommt bei mir nur, wenn ich console.dir(units) ausführe. Kurz: das Array enthält ein Element nämlich units[0] und das ist "%".Bekomme ich diese Liste:
Es ist ein Array, das die Einheiten enthält. Mach damit, was immer Du willstWas kann ich nun mit diesem Ergebnis machen, damit ich die fontsize auslesen kann?
<style>
body{font-size: 110%;}
</style>
var vTag = document.getElementsByTagName("body");
[B]console.log(vTag[0].style.fontSize);[/B]
var vTag = document.getElementsByTagName("body");
undefined
vTag[0].style.fontSize = '150%';
"150%"
[B]console.log(vTag[0].style.fontSize);[/B]
150%
Mit dem gezeigten Code kannst Du feststellen, welche Einheiten im CSS (sowohl im Stylesheet als auch im inline Style) verwendet werden, also auch ob pt oder px.Ich möchte wissen ob im CSS die Einheiten pt oder px verwendet werden für die Schriftgröße,
Mit dem gezeigten Code kannst Du feststellen, welche Einheiten im CSS (sowohl im Stylesheet als auch im inline Style) verwendet werden, also auch ob pt oder px.
<style>
body{font-size: 110%;}
h1{font-size: 110px;}
</style>
var units = Array.from(new Set(Array.from(document.getElementsByTagName("*"))
.map(function(e) { return e.style.getPropertyValue('font-size') })
.filter(function(fs) { return /^\d+[^0-9]+$/.test(fs) })
.map(function(fs) { return fs.match(/[^0-9]+$/)[0] })))
["%"]
0: "%"
Ja, der Code von Dir verwendete Code zeigt die Einheiten, die im style-Attribut der Elemente auftreten.Das ich px verwendet habe zeigt das Ergebnis nicht.
<h1 style="font-size: 12px;">
, würde Dir der Code die px anzeigen. Die Angaben aus dem Stylesheet findest Du dagegen mit dem Code aus Kommentar #7.