css - Html scrollable div with persistent border that tightly envelops visible scrolled content size -
let's imagine have list container (a div in code below) need able resize viewport visible on. need border around list's content (border has "brown" color in example). here problem.
if list content fits in viewport without scrolling border must envelop list content tightly (so can't set border div "column left" because don't need border around whole large area can potentially contain list items).
if viewport small , list content scroll border must persist (i miss @ container's top , bottom in vertial list example).
that's pretty common behaviour gui.
.bkgnd { position: absolute; background-color: grey; top: 0; bottom: 0; right: 0; left: 0; } .column{ overflow: auto; position: absolute; } .left{ width: 460px; top: 100px; bottom: 70px; left: 17px; } .listitem{ background-color: yellow; margin: 5px 0 0 0; } .listitem:first-child{ margin: 0; }
<!doctype html> <html> <head> <meta charset="utf-8" /> </head> <body> <div class="bkgnd"> <div class="column left"> <div style="padding: 5px; background-color: brown;"> <div class="listitem">item</div><div class="listitem">item</div><div class="listitem">item</div> <div class="listitem">item</div><div class="listitem">item</div><div class="listitem">item</div> <div class="listitem">item</div><div class="listitem">item</div><div class="listitem">item</div> <div class="listitem">item</div><div class="listitem">item</div><div class="listitem">item</div> <div class="listitem">item</div><div class="listitem">item</div><div class="listitem">item</div> <div class="listitem">item</div><div class="listitem">item</div><div class="listitem">item</div> </div> </div> </div> </body>
this work better if give divider around list items id , set styles above rest of css. there reason wouldn't work situation?
in html:
<div id="testing"> <div class="listitem">item</div><div class="listitem">item</div><div class="listitem">item</div> <div class="listitem">item</div><div class="listitem">item</div><div class="listitem">item</div> <div class="listitem">item</div><div class="listitem">item</div><div class="listitem">item</div> <div class="listitem">item</div><div class="listitem">item</div><div class="listitem">item</div> <div class="listitem">item</div><div class="listitem">item</div><div class="listitem">item</div> <div class="listitem">item</div><div class="listitem">item</div><div class="listitem">item</div> </div>
in css:
#testing { border: 5px solid brown; background-color: brown; overflow: auto; position: absolute; width: 450px; max-height: 100%; top: 0px; left: 0px; }
then change .column class properties overflow visible.
.column{ overflow: visible; position: absolute; }
side note: if you're looking make responsive webpage, should using percentages rather pixels possible. also, there reason you're preferring use div elements instead of list elements?
Comments
Post a Comment