It was noticed that when fancybox is calculating how wide it needs to be to fit the content, it doesn't handle decimal places/floating point numbers.
For example if we had 2 <div>
of 300px
and 217.367px
respectively, fancybox would round the width
of its content to 300px + 217px = 517px
. This means the second div
would not fit and would therefore drop down to the next line.
It seems this is due to the use of the jQuery width()
method.
Relevant code
html :
<a class="fancybox" href="#inline">open inline</a>
<div id="inline" class="cf">
<div id="content">
<h3>Lorem Ipsum</h3>
<p>More text content etc</p>
</div>
<div id="red">Other floating content</div>
</div>
css :
#inline {
position: relative;
white-space: nowrap;
}
#content {
width: 15.526em; /* 217.367px */
height: 150px;
display: block;
float: left;
}
#red {
height: 150px;
width: 300px;
display: block;
float: left;
}
jQuery :
$(".fancybox").fancybox({
padding: 0
});
Notice in the fiddle the #inline
container is always visible for demonstration purposes only. Also notice the width
of one of the containers was set in ems
, which is a pretty common scenario so changing it to a fixed width
in px
may not be the way to go (although it's possible to set width: 217.367px
on the css with the same result)
Is there a fix or a workaround?
A possible and easy solution would be to add an extra pixel to the fancybox container but it would be better to add it only when it's needed and not as a general rule.