I have defined an element in HTML with a width of 23% (defined in CSS). When I try to get the width of the element using JavaScript, in the console, it returns the wrong value. I'd expect it to return the same as what's returned when running the following:
$('#child').parentElement.offsetWidth * 0.23
Console output - actual vs expected width:
As you can see in the image above, the values are different by 0.23 pixels. I see that the magnitude of the difference changes depending on the screen size. What am I missing?
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="jquery-ui.min.css" />
<style>
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
#child {
position: absolute;
width: 23%;
height: 50px;
background-color: orange;
}
</style>
</head>
<body>
<div id="child"></div>
</body>
</html>