How to set div height with relative position as child div with absolute position using css? - css-position

parent div height should be adjusted to child div height so that parent does not overlap each other. How to do that?
http://jsbin.com/zeluke/edit?html,css,output

I am not sure what is being asked here, that is, parent and child height/width/position should not overlap? or as in the example, childs should be in separate positions?
First, Keep parent div with relative position and set its width/height. Here parent div without height/width are dimensionless, looking like overlapping.
Then, second, for childs with absolute position, have their height/width/(left,right,top,bottom) properties set. Position elements are used with (left,right,top,bottom) properties which have default values as auto, browser sets that and as you can it is same for both childs ie childs are in same position relative to their parents. These 2 steps will make child and parent being in their own places. You can also look into adding margin/padding for them for more separation in visuals.
Please remember, absolute position is position relative to the nearest positioned ancestor. Also, do consider using (left,right,top,bottom) properties.

Related

Is it possible for a red black tree to have a node being black, node's parent being black, but the parent has no siblings?

I'm reading through red black tree chapter from the book "introduction to algorithms" by Cormen. In that delete chapter, it basically says if both the node and node's parent are black, then the sibling of node's parent has to exist. The text is in page 327 first paragraph.
I don't get the logic for it, like how do we deduct something like that? Is that even true?
Though I did try to implement my own version of RB Tree and I couldn't produce a tree with a subtree like
/
R
/
B
/ \
B ...
/
...
or
/
B
/
B
/ \
B ...
/
...
Basically both node and parent are black but parent doesn't have sibling. Can't produce it so far
The text is correct. The only time you can have a black node with no sibling is when the node in question is the tree root. The easy way to think of this is to draw out the B-tree equivalent, Moving red nodes up so they are part of the same block as their parent black node. When you do this it becomes easy to see that a non-root black node with no sibling is going to produce an unbalanced tree.
In fact the two options for a non-root non-leaf black node are that either the sibling is black, or the sibling is red and has two black children (even if those two children are leaf nodes and simply represented by a null value in the implementation).
SoronelHaetir is right. But there are 3 things to say about fixups of deletes:
When "sibling" is talked about, this is normally the sibling of the current Node. It is not usually parent's sibling. So if the current Node is the left child of the parent then the "sibling" is the right child of the parent.
You say "I don't get the logic for it, like how do we deduct something like that? Is that even true?". Yes it is. One of the rules is the total black Node count down every path is the same.
So in a correct RB tree, for a given node, if the left child is black, then the right child is black (or it is red and it has 2 black children). For a correct RB Tree, you cannot have any node with an unbalanced count of black nodes down all paths. The count has to be the same in every path.
The other situation where you have unbalanced black tree count is where a leaf node has been deleted and it is black, and you are in the process of restoring the black tree count. Until it is restored (which can always be done), the tree is not a valid RB Tree.

Nested list (tree) - how to nest elements by dragging to the right?

What would be the approach with Vue.Draggable/SortableJS in order to achieve the functionality as shown in this animated gif?
The default behavior of Sortable for nesting is to drag the element up to the above element until the mouse reaches emptyInsertThreshold pixels from the drop zone of the above element but I would like to be able to nest elements by dragging them to the right. Same for un-nesting.
I have set emptyInsertThreshold to 0 to disable the default behavior and now when I drag the element to the right I get the following events fired: clone and start (in that order).
But how do I:
Can get notified when the mouse has traveled the pre-defined distance to the right?
Inform Vue.Draggable that the ghost element should be nested as a child to the element under which I am doing the horizontal movement?
You can get the mouse position given in the start event under event.originalEvent and in the onMove event using the originalEvent argument (2nd argument). I would track the % that the mouse is past the end of the list item above the dragged item, using: (clientX - aboveItemStart) / aboveItemWidth. Then when it reaches 10% or so, change the DOM directly using event.dragged. Not sure how you would modify it to work with Vue.Draggable... you might need to edit the Vue.Draggable source.

How to get width/height of a movie clip in CreateJs?

In AS3.0 it is like:
mc.width and mc.height
In AS2.0 it is like:
mc._width and mc._height
What about createJs
mc.????
If the MC was generated by Flash then you can use either myMC.nominalBounds, which returns the first frame's bounds, or myMC.getBounds() which returns the current frame bounds. These values will represent the author-time dimensions, and will not reflect changes you made to the contents of the MC in code.
If the MC was not generated by Flash, then you can still call getBounds(), but it will not include bounds for Shape instances (unless you have set bounds on them with setBounds()).

Knob drags beyond right boundary [More 1.5.1]

When creating a nice slider using Mootools More 1.5.1 Slider class, I noticed that the 'knob' can be dragged too far to the right.
Consider this slider scenario:
|--|~|----------------|
I find I am able to do this:
|---------------------||~|
which is no good when the parent div has overflow:hidden set.
This occurs because the Drag object in the Slider class sets the left most x position ( limit.x[1] ) as the width of the passed in element (parent of the knob).
I would expect this limit to be the the element width minus the knob width.
I get the same problem whether the 'knob' is inside or outside the 'element' (above and below in the DOM).
The only way I could fix this was with a hack:
if(mySlider.drag.options.limit.x[1]===mySlider.element.getSize().x){
mySlider.drag.options.limit.x[1] -= mySlider.knob.getSize().x;
mySlider.drag.setOptions(mySlider.drag.options);
}
Check out this Fiddle (examples of broken and hacked).
Am I missing something here? Or should this be raised as a bug?

position a child sprite to the same position as the parent?

I have a sprite which also has a child sprite. I am trying to understand how to properly set the child sprite's position so that it matches the same screen position as the parent. I thought based off of reading the docs, that I should just be able to do:
child.position = [child convertToNodeSpaceAR:parent.position];
however, that does not give the correct position.
I know I can do:
child.position = ccp(parent.textureRect.size.width * parent.anchorPoint.x,
parent.textureRect.size.height * parent.anchorPoint.y);
but I thought the convertToXXSpace methods were supposed handle this as a convenience?
Try:
child.position = [parent convertToNodeSpace:parent.position];
You want to take a position and convert it to the parent's coordinate space, which is why you call this on the parent class.
Edited:
On second thought you have a child attached to a parent and you want the child's position to match the same position as the parent. To do this try adding the child to the parent and using a position of (0,0) for the child:
[parent addChild:child];
child.position = CGPointZero;
Technically you should not have to touch the child's position afterwards. If you move the parent the child will automatically move with it. The only time you will change the child is if you are offsetting it from its parent, which based on your OP you are not.