Aligning a range next to a div inside a tr creates a gap between them
Usage inline-block
will create space when items are on a new line. (The most frustrating example is when you want to li
be side by side.
Or do the following:
<div id="headerDiv" style="">DIV</div><span id="labelSpan">test</span>
Or that:
<div id="headerDiv" style="">DIV</div><!--
--><span id="labelSpan">test</span>
Alternatively, you can do float:left;
this instead.
source to share
inline-block
always gives a space. If you don't want this, you can do this:
Remove space
<table>
<tr>
<td>
<div id="headerDiv" style="">DIV</div><!--
--><span id="labelSpan">test</span>
</td>
</tr>
</table>
Fiddle: http://jsfiddle.net/praveenscience/w3sjrgc4/2/
Or use float
:
<table>
<tr>
<td>
<div id="headerDiv" style="">DIV</div>
<span id="labelSpan">test</span>
</td>
</tr>
</table>
td {
overflow: hidden;
}
td > span {
float: left;
border:2px solid;
}
td > div {
float: left;
border:2px solid;
}
Fiddle: http://jsfiddle.net/praveenscience/vt4kr35w/
source to share
This spacing is caused by spaces (both elements have inline layout), you can read them:
- pushing elements next to each other on the same line in HTML markup;
Example:
<td>
<div id="headerDiv">DIV</div><span id="labelSpan">test</span>
</td>
- using
<!-- -->
tags ;
Example:
<td>
<div id="headerDiv">DIV</div><!--
--><span id="labelSpan">test</span>
</td>
- using
word-spacing
CSS property.
CSS
td {word-spacing: -100%;}
source to share
It is named white space
and occurs between inline (or inline blocks) elements when there is room in the markup (on the same line or newline).
Below are some solutions :
Solution 1 - Remove the space in the markup:
<div id="headerDiv" style="">DIV</div><span id="labelSpan">test</span>
Demo : http://jsfiddle.net/w3sjrgc4/7/
Solution 2 - Set the font-size
value to 0 in the container, then remove it for children.
Demo : http://jsfiddle.net/w3sjrgc4/9/
Solution 3 - Comment out the space in the markup:
<div id="headerDiv" style="">DIV</div><!--
--><span id="labelSpan">test</span>
Demo : http://jsfiddle.net/w3sjrgc4/10/
Solution 4 - On the left, float children and empty the container to keep the flow of documents up and running.
source to share