Look at this fiddle
HTML:
<div id="outer">
<div id="inner">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li>10</li>
</ul>
</div>
</div>
<button onClick="toggleOuterHeight();">toggle outer div height</button>
JS:
toggleOuterHeight = function() {
if ($('#outer').css('height') == '400px') {
$('#outer').css('height','200px');
} else {
$('#outer').css('height','400px');
}
}
CSS:
#outer {
background-color: #1abc9c;
height: 400px;
position: relative;
overflow: auto;
}
#inner {
background-color: #16a085;
height: 250px;
width: 250px;
position: absolute;
margin: auto;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
#inner ul {
margin: 0;
}
#inner ul li {
line-height: 25px;
}
I have a div (inner) vertically aligned inside another div (outer)... It works like a charm!
If the outer div is smaller than the inner div scrolling must occur. You can see this clicking on button on the bottom of the example.
There is the problem: scrolling hides the top of the inner div. You cannot scroll to show the first lines!!!
I changed the css to center the div using translate, no luck!
Any tips?