How can I expand the parent div(auto) when the child div(fixed width) is shown onclick?
Objective: When I click the link, the child div will appear and the parent div should expand(scale) to the width of the child div. The child div should not overflow outside of the parent div.
Thanks :)
JS:
$(function() {
$('#mylink').click(function() {
$('#mybox').show();
});
});
HTML:
<a id="mylink" href="javascript:void(0);">SHOW BOX</a><hr />
<div class="parent">
<div class="header">Header Content</div>
<div id="mybox" class="child">Content</div>
</div>
CSS:
body {
font-family:verdana;
font-size:10px;
}
.parent {
border:1px solid blue;
}
.child {
display:none;
width:400px;
border:1px solid red;
background:lightblue;
}
.header {
width:auto;
border:1px solid green;
}