To set the height of a div
as a percentage, the container of the div
needs to have an explicit height on it.
Take a look at my example: JSFiddle.
.message_wrap {
height:500px;
}
.message_box {
border:1px solid #bbb;
background-color: #B0E0E6;
padding: 10px;
width:350px;
height:20%;
overflow-y:scroll;
overflow-x:hidden;
}
HTML
<div class="message_wrap">
<div class="message_box">
<p class="message">Collaboratively administrate empowered markets via plug-and-play networks. Dynamically procrastinate B2C users after installed base benefits. Dramatically visualize customer directed convergence without revolutionary ROI.</p>
<p class="message">Completely synergize resource sucking relationships via premier niche markets. Professionally cultivate one-to-one customer service with robust ideas. Dynamically innovate resource-leveling customer service for state of the art customer service..</p>
<p class="message">Efficiently unleash cross-media information without cross-media value. Quickly maximize timely deliverables for real-time schemas. Dramatically maintain clicks-and-mortar solutions without functional solutions.</p>
</div>
</div>
An alternate solution would be change the max-height
to vh
units. That is viewport-height
.
would be height:20%;
height:20vh;
It would effectively set .message_box
to 20% of the viewport height, thus no longer needing an explicit height set on the parent.