Created
November 20, 2022 00:45
-
-
Save greggman/dee48b7642bf7b1e0a5e2fc9b80e6fe0 to your computer and use it in GitHub Desktop.
Display size is not a multiple of CSS size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#parent { | |
display: flex; | |
width: 99px; | |
justify-content: space-between; | |
} | |
#parent>* { | |
flex: 1 1 auto; | |
height: 20px; | |
min-width: 0; | |
} | |
#left { | |
background-color: red; | |
} | |
#right { | |
background-color: blue; | |
} | |
pre { | |
margin: 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="parent"> | |
<div id="left"></div> | |
<div id="right"></div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function main() { | |
log('devicePixelRatio:', devicePixelRatio); | |
const parent = document.querySelector('#parent'); | |
parent.style.width = `${99}px`; | |
const left = document.querySelector('#left'); | |
const right = document.querySelector('#right'); | |
const observer = new ResizeObserver(logSizes); | |
observer.observe(left); | |
observer.observe(right); | |
}; | |
/** | |
* @param {ResizeObserverEntry[]} entries | |
*/ | |
function logSizes(entries) { | |
if (!entries[0].devicePixelContentBoxSize) { | |
log('WARNING!!! browser does not support getting the actual display size'); | |
} | |
for (const entry of entries) { | |
const size = entry.devicePixelContentBoxSize || entry.contentBoxSize; | |
log('id:', entry.target.id.padEnd(5), 'displayWidth:', size[0].inlineSize, 'cssWidth:', entry.target.getBoundingClientRect().width); | |
} | |
} | |
function log(...args) { | |
const elem = document.createElement('pre'); | |
elem.textContent = args.join(' '); | |
document.body.appendChild(elem); | |
} | |
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"name":"Display size is not a multiple of CSS size","settings":{},"filenames":["index.html","index.css","index.js"]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment