Hello everyone, the problem is as follows:

1) 900px parent block, the children contain pictures, at this stage the height of the parent block became 900px .

2) After loading the pictures, the child blocks are aligned in a special way using jquery-ui.position () . The child elements lay as it should, tightly, but the height of the parent unit is still 900px , although the child elements take 2 times less space.

3) I came to the conclusion that this is due to the fact that the children, after alignment with jquery-ui.position (), get the properties left and top . If you remove disable positioning, then the parent resizes as needed.

How to make the height of the block rubber in relation to the content, if the child blocks are built using the properties of left / top ?

 <div class='content'> <div class='item'></div> <div class='item'></div> <div class='item'></div> <div class='item'></div> </div> 

Styles:

 .content{ overflow: hidden; width: 100%; position:relative; display: block; height: auto; padding: 0; } .item{ position: relative; display: inline-block; } 

Code:

  SFW.prototype._fillCollection = function(way){ var _this = this; /*Ρ‚ΠΎΡ‚ самый Ρ€ΠΎΠ΄ΠΈΡ‚Π΅Π»ΡŒ, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Π½Π΅ рСсайзится*/ var content = $('<div class="content"></div>') .appendTo(this.viewBlock) .data('count', 0); var items = this._data[way.firstLevel].items[way.secondLevel].items; var elements = []; /*Π΄Π΅Ρ‚ΠΈ*/ for(var k = 0; k < items.length; k+=1) { var wrapItem = $('<div class="item"></div>') .appendTo(content) .data('data', items[k]); var item = $("<img>") .data('data', items[k]) .attr("src", items[k].PICTURE_FACE) .appendTo(wrapItem) .load(function(){ _this._waitAllImg(content); }); elements.push(wrapItem); } content.data('elements', elements); }; /*ΠΆΠ΄Ρ‘ΠΌ Π·Π°Π³Ρ€ΡƒΠ·ΠΊΠΈ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠΉ*/ SFW.prototype._waitAllImg = function(content){ content.data('count', content.data('count') + 1); if(content.data('count') === content.data('elements').length){ this._regularizeImg(content); } }; /*упорядочиваниС Π΄Π΅Ρ‚Π΅ΠΉ*/ SFW.prototype._regularizeImg = function(content){ var elements = content.data('elements'); for(var i = 0; i < elements.length; i +=1){ var of, my, at, elem, data; elem = elements[i]; data = elem.data('data'); of = data.of; my = data.my; at = data.at; /*Если Π·Π°ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ строчку Π½ΠΈΠΆΠ΅,Ρ‚ΠΎ Π΄ΠΎΡ‡Π΅Ρ€Π½ΠΈΠ΅ элСмСнты Π΄ΠΎΠ±Π°Π²Π»ΡΡŽΡ‚ΡΡ ΠΊΠΎΠ½Π΅Ρ‡Π½ΠΎ Π½Π΅ Ρ‚Π°ΠΊ ΠΊΠ°ΠΊ Π½Π°Π΄ΠΎ, Π·Π°Ρ‚ΠΎ Ρ€ΠΎΠ΄ΠΈΡ‚Π΅Π»ΡŒ мСняСт свой Ρ€Π°Π·ΠΌΠ΅Ρ€ ΠΏΠΎΠ΄ содСрТимоС*/ elements[i].position({my: my, at: at, of: of}); } }; 

PS I need this in order for my parents to line up one after another, in a list, and it turns out that at the end of each new parent there is an empty space.

  • Attach the screen i.imgur.com/bVH928F.png - Metamorphosis
  • Why is the height 900. If you have a car in the code?! And how can the child elements be aligned using positions if the block has relativism? Can you show the js code? - HoPkInS
  • I went to the link that you specified. Here the height of the parent is not set to js, ​​the height is immediately registered through css. And if you set the height for it to auto. That is, all the rules become. s020.radikal.ru/i713/1511/23/6b821025502c.png - HoPkInS
  • HoPkInS, the height becomes 900 due to the initial layout of the children, before positioning. 900 is the number DevTools shows me, height is still auto. top and left work if the current and child elements are relative: htmlbook.ru/css/top . Code now add to the post - Metamorphosis
  • I solved the problem by manually counting the block height on Js. But the question remains. - Metamorphosis

0