css - Optional non-scrolling header in a fixed-height element -


i have fixed-size box set scroll when overflows. however, has header, , doesn't; , can't figure out way style when header appears. know why happens (the header pushes 100%-height scrolling element down , out of container), can't figure out non-table way fix it. here's fiddle showing problem; , full code archives:

html:

<div class="fixed-size">   <ul class="scrollable">     <li>one</li>     <li>two</li>     <li>three</li>     <li>four</li>     <li>five</li>     <li>six</li>     <li>seven</li>     <li>eight</li>     <li>nine</li>     <li>ten</li>   </ul> </div>  <div class="fixed-size">   <div class="stays-at-top">       header   </div>   <ul class="scrollable">     <li>one</li>     <li>two</li>     <li>three</li>     <li>four</li>     <li>five</li>     <li>six</li>     <li>seven</li>     <li>eight</li>     <li>nine</li>     <li>ten</li>   </ul> </div> 

css:

.fixed-size {     height: 100px;     width: 200px;     display: inline-block;     background-color: #fcc; }  .scrollable {     height: 100%;     width: 100%;     overflow-y: auto; }  .stays-at-top {     background-color: #f99; }​ 

if it's not clear, want header (.stays-at-top) stay @ top (i.e. not scroll friends).

http://jsfiddle.net/eypqw/6/

.fixed-size {     width: 200px;     display: inline-block;     background-color: #fcc; } .scrollable {     height: 100px;       overflow: auto;     } .stays-at-top + .scrollable {     margin-top: 17px;     height: 83px;      } .stays-at-top {     background-color: #f99;     position: fixed;     width: 200px; }​ 

this should meet full requirements.

.fixed-size specifies width, not height.

.scrollable specifies height , overflow: auto allow contents scroll.

.stays-at-top + .scrollable matches when have .stays-at-top , .scrollable element adjacent each other, i.e. when have fixed header. here add margin-top enable first item clear fixed header, , reset height value value specified in .scrollable minus margin-top value.

.stays-at-top requires position: fixed , width matching width in .fixed-size.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -