Update after editing a question
The reason your main falls under aside is because you have invisible space, in your case a line break, but it could also be a simple space between your elements in your markup, which the size actually adds along with the elements, which make it more than 100% wide, so create a scroll bar.
This space, which exists for inline elements (which are not positioned absolute or fixed or floating), must be taken into account together with the size of the elements when calculating their width in order to match the width of their parents (in this case, body / viewport).
Here you can learn more about this and how to get rid of it or make it size 0 (if you save the inline elements).
Other ways to align elements side by side is to use display: flex or display: table-cell , both with similar behavior and with built-in elements (in the sense of laying horizontal as opposed to block elements that flow vertically), although it does not suffer from white space in the same way when it comes to its fixed size compared to the actual size.
To clarify, i.e. if the value on the flex element is 14.5%, it is 14.5% and no more, unlike the built-in, which is 14.5% plus a space (where the size of the free space actually depends on the font size set)
display: flex example display: flex (recommended)
* { box-sizing: border-box; } html, body { margin: 0; height: 100%; } body { display: flex; height: 100%; } aside { width: 14%; margin-right: 0.5%; background-color: #f66; } main { width: 85.5%; background-color: #66f; }
<aside> aside </aside> <main> main </main>
display: table-cell example display: table-cell (for older browsers)
* { box-sizing: border-box; } html, body { margin: 0; height: 100%; } body { display: table; width: 100%; height: 100%; } aside { display: table-cell; width: 14%; background-color: #f66; } main { display: table-cell; width: 85.5%; background-color: #66f; } .margin { display: table-cell; width: 0.5%; }
<aside> aside </aside> <div class="margin"></div> <main> main </main>
Note:
Other ways to make the difference between aside and main when using display: table is to use cell fill, border width, etc.
With your existing code, and since you are not using a regular thread, absolute positioning may be an option.
<!DOCTYPE html> <html> <body> <aside></aside> <main></main> <script> var h = screen.height/100; var w = screen.width/100; var e = document.getElementsByTagName("aside")[0].style; e.position = "absolute"; e.backgroundColor = "lightblue"; e.width = 14*w + "px"; e.height = 69*h + "px"; e.marginRight = 0.5*w + "px"; e = document.getElementsByTagName("main")[0].style; e.position = "absolute"; e.backgroundColor = "green"; e.width = 85.5*w + "px"; e.height = 69*h + "px"; e.left = 14.5*w + "px"; e = document.getElementsByTagName("body")[0].style; e.margin = e.padding = "0"; e.backgroundColor = "black"; </script> </body> </html>
Update 2
The problem with your code is that it starts until the DOM completes completely, so create scrollbars. Try the example below, where I added a delay, and you will see that it works (when the browser works as much as possible).
<!DOCTYPE html> <html> <script> function runOnLoad() { setTimeout(function() { var h = screen.height/100; var w = screen.width/100; var e = document.getElementsByTagName("aside")[0].style; e.display = "inline-block"; e.backgroundColor = "lightblue"; e.width = 14*w + "px"; e.height = 69*h + "px"; e.marginRight = 0.5*w + "px"; e = document.getElementsByTagName("main")[0].style; e.display = "inline-block"; e.backgroundColor = "green"; e.width = 85.5*w + "px"; e.height = 69*h + "px"; e = document.getElementsByTagName("body")[0].style; e.margin = e.padding = "0"; e.backgroundColor = "black"; e.fontSize = "0"; }, 200) } </script> <body onload="runOnLoad();"> <aside></aside> <main></main> </body> </html>