views:

2349

answers:

2

Note that my question is not about how to fill remaining space with <div>.

Background: I'm trying to use jQuery sortable with a series of horizontally laid out <div>, with class "column"

.column
{
  display:inline-block;
}

Now in FF, everything looks good. During dragging, the "placeholder" which jQuery sortable injects is an empty <div> with

<div class="column ui-sortable-placehold" 
     style="visibility:hidden;height:[hh]px;width[ww]px;"/>

The "inline-block" will cause this "placeholder" to span however many [ww]px the <div> being dragged has.

(I have option "forcePlaceholderSize = true")

However, this breaks down in IE7 as it only knows display:inline. But if I change to use "display:inline" on FF, the placeholder will no longer span [ww]px.

I've tried numerous workarounds, including:

  • specifying my own placeholder style.
  • switching css based on jQuery.browser.msie.
  • dynamic css expression.

none of them works satisfactorily due to one reason or another.

It seems to me like if only I can force a size on empty div, I will be able to solve this problem neatly. (Of course, the neatiest solution is always for the @#$% IE to be standards compliant to begin with...)

Good workarounds welcome.

Please help!

+6  A: 
.column {
    /* your stuff here */
    width: 100px;
    height: 200px;
}

You can also play with related CSS properties like min-width and max-height, but there are IE6 limitations with those, I believe.

Warren Young
Thanks for the response, Warren. jQuery actually already adds width/height to the placeholder div as shown above. And I need it to set it for me since each draggable block is of different size. I also clarified my question by emphasizing that the div is "visibility:hidden". It seems that hidden divs do take up space only if its "display:inline-block" ?
Xerion
I don't see why you expect something that's hidden to take space. Hidden means no visible effect on your document. It seems you want the div to be empty but just take space. If so, you can remove the 'hidden' and 'display' styles entirely. Since the div has no content, it will just be a space-taking block in your document. You can later fill the div with content, and its size won't change, assuming you also set 'overflow: none'.
Warren Young
This is not true. There is a difference b/w "display" and "visibility". According to this page http://stackoverflow.com/questions/1479239/how-to-force-an-hiddenempty-div-to-take-up-space"when visibility is set to hidden, the element being hidden still occupies its same place in the layout of the page. "As I explained in my post, jQuery-ui-sortable plugin inserts the placeholder div as an empty+hidden element. I dont want to mod the plugin code, so was looking for ways to make it take up space w/o "display:inline-block" which doesn't work on IE7.
Xerion
+3  A: 

The classic way to make empty elements to take space is to add &nbsp; inside them. Would that help in this case?

hrnt
That is a famous yet very ugly hack. Use css instead.
There's nothing wrong with being explicit though - it may not be pure CSS but it works.
Shaun F