html - Stretch background image width but crop height -
how make background img would:
- stretch across window horizontally
- have fixed height
- crop height when it's bigger content's height (do not shrink)
currently have code implements #1 , #2 can't seem make #3:
<img class="background" src="images/page-background.png"/> html { position: relative; } .background { width: 100%; height: 2800px; position: absolute; top: 0; left: 0; z-index: -1; } i tried moving img inside div overflow: hidden didn't work reason:
<div class="background-wrap"> <img class="background" src="images/page-background.png"/> </div> .background-wrap { position: absolute; width: 100%; height: 1000px; overflow: hidden; z-index: -1; } how in css / html (without javascript)?
you use css background-image on div so:
.background-wrap { background: url(images/page-background.png) no-repeat; background-size: 100% 500px; } the background-size specifying that; stretch 100% across window horizontally, , have 500px fixed height (change auto if want image height scale in proportion width).
Comments
Post a Comment