Firstly - box model
Your border is adding size to the box, most people use box-sizing
as a default these days
* {
box-sizing: border-box
}
(if you've the option, just throw it in your global CSS and be done with it)
Highly recommend reading up on the box model, a basic understanding of that will save you much pain (or at least help you search for answers!)
With your example:
<div style="background:blue;width:500px;height:40px">
<div style="box-sizing:border-box; border:1px solid red;height:40px;font-size:0px;display:inline-block;width:30%;">
</div>
<div style="box-sizing:border-box; border:1px solid black;height:40px;font-size:0px;display:inline-block;width:70%">
</div>
</div>
Secondly - inline-block
elements
You're facing a common issue with inline block elements where whitespace between tags is affecting your rendered content.
Generally best just to use flexbox or if you're restricted to old browsers, float
s
Using flexbox
<div style="background:blue;width:500px;height:40px;display: flex;">
<div style="box-sizing:border-box; border:1px solid red;height:40px;font-size:0px;width:30%;">
</div>
<div style="box-sizing:border-box; border:1px solid black;height:40px;font-size:0px;width:70%">
</div>
</div>
Using float left
<div style="background:blue;width:500px;height:40px;/* display: flex; */">
<div style="box-sizing:border-box;border:1px solid red;height:40px;font-size:0px;width:30%;float: left;">
</div>
<div style="box-sizing:border-box;border:1px solid black;height:40px;font-size:0px;width:70%;float: left;">
</div>
</div>
If you really have to use inline-block
See my links above for workarounds, all of which are unsatisfactory in some way, eg.
<div style="background:blue;width:500px;height:40px">
<div style="box-sizing:border-box; border:1px solid red;height:40px;font-size:0px;display:inline-block;width:30%;">
</div><!-- commenting out carriage return
--><div style="box-sizing:border-box; border:1px solid black;height:40px;font-size:0px;display:inline-block;width:70%">
</div>
</div>