Thursday 15 March 2012

javascript - JS - why is there space between divs in normal flow -



javascript - JS - why is there space between divs in normal flow -

this question has reply here:

why there space between li elements? [duplicate] 5 answers

i wanted position 2 divs side side based on size of container div. sec div positioned below first because there 4 pixel gap between them somehow. why , more importantly that? margins, padding , border 0px create cleaner.

<div id='container' width='300'> <div id='left' width='150'></div> <div id='right' width='150'></div> </div>

i know can utilize float accomplish goal want know cause.

jsfiddle here.

also have noticed when width() of element didn't same number what's in debug window. clue?

thanks!

edit: ok, see know it's ' ' between them because of new line character. doesn't seems matter if it's 'inline-block' or 'block' though. setting container display 'flex' appears solution.

(also give thanks suggestions on how remove space if there white space characters between divs! still can't upvote sadly because of low reputation...)

compare:

<div> b </div>

with:

<div> ab </div>

elements display: inline-block treated text.

there space between them because inline elements white space characters between them in markup.

put start tag sec div after end tag first one, without spaces, tabs or new lines between them.

javascript html css width

No comments:

Post a Comment