css - Using background-size with relative height -


how set background of div container giving relative height (no content in div besides background itself).

the code below works fine, gives div absolute hight of 350px. when ever rescale browser window, there gap between div , content follows after 350px.

#div  { background: url("bg.jpg") no-repeat; background-size: 100% auto; height: 350px; width: 100%; } 

if want div have full height, make div, html, , body have height of 100% no margin fill full screen:

html, body, #div {     height: 100%;     width: 100%;     margin: 0px; } 

then, set background cover without overflow:

#div {     background: url("http://placehold.it/350x150") no-repeat center;     -webkit-background-size: cover;     -moz-background-size: cover;     -o-background-size: cover;     background-size: cover;     width: 100%;     overflow: none; } 

fiddle: fiddle

this positions background in center horizontally, cutting off left or right overflow.

this assumes background longer horizontally vertically, sounds question. if not, should fix background , center vertically well.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -