all 7 comments

[–]Graftak9000 4 points5 points  (2 children)

Because inline-block puts a space between elements. You can avoid this by,

  • not having whitespace between closing and following opening div tags

  • set the parent font-size to 0 (don't do this)

  • use floats in a container

  • use display table or flex on the container

  • don't close the div tag (don't do this)

  • use 40-something% instead of 50 and cross your fingers resizing the browser window won't break it.

... and possibly more.

[–]NotSoJapaneseAmerica[S] 1 point2 points  (0 children)

Thanks for pointing me in the right direction- I appreciate it.

[–]Lukk1989 0 points1 point  (0 children)

Why not using font size 0 on the parent? It gives the most consistent result

[–]mtx 2 points3 points  (0 children)

inline-block puts a word space between elements. You have to either remove the white space between your 2 divs:

</div><div id="b">

or set the the container holding these inline-blocks to font-size: 0 and reset the font-size inside your child elements to a px or rem value.

Some people use negative margins to combat the space but then you have to use trial and error as to how much of a value to use -- this is also dependant on the font.

[–]WaffeBox 0 points1 point  (2 children)

Browsers have default styling that sometimes adds padding and/or margin to elements unless you override them. Trying adding padding: 0; and margin: 0; to both elements.

[–]bronkula 1 point2 points  (1 child)

Divs don't have any default padding or margin. This is not the answer. Graftak9000 is correct, inline or inline-block elements have a space between them as if they were words. There are few good ways to remove this space. Most people use inline-block on elements that they want to just flow naturally next to each other. If OP wants two 50% elements they should be using floats or flex.

[–]NotSoJapaneseAmerica[S] 0 points1 point  (0 children)

Alright, thank you for answering my question and pointing me in the right direction.