responsive design - background-image height to properly scale down in css? -
i have built grid layout content , want use images inside div column background. @ first placed image class of "img-responsive inside div columns , works perfectly. want achieve same effect have image background instead. having trouble getting background-image height scale width of div. img-responsive class have 'width: 100%;' , 'height: auto;' how apply same logic background-image? can't set div column class height: auto; or have max-height of n pixels because displays nothing. below example of code, top 2 divs what want background images like. can explain me how can achieve this?
body { margin: 0 auto; padding: 30px 30px 5px 30px; font-family: sans-serif; color: black; font-size: 1.2em; } section { width: 80%; margin: 0px auto; line-height: 1.5em; font-size: 0.9em; padding: 30px; color: black; overflow: hidden; } .row { margin: 1% auto; width: 100%; overflow: hidden; padding-bottom: 10px; } .row::after { content: ""; display: table; clear: both; } .col { line-height: 0; margin-left: 1%; margin-right: 1%; margin-top: 1%; margin-bottom: 1%; display: inline-block; float: left; overflow: hidden; } .col:first-child { margin-left: 0px; } .col:last-child { margin-right: 0px; } .img-responsive { max-width: 100%; height: auto; } .col.col-6 { width: 47%; height: auto; border: 2px solid black; margin-left: 1%; margin-right: 1%; } .col.col-6-bg { width: 47%; max-height: 1000px; min-height: 145px; min-height: 200px; margin-left: 1%; margin-right: 1%; border: 2px solid black; } .img-bg { background-image: url("http://prasinostcharles.com/wp-content/uploads/2014/09/gallery-large_food_cod.jpg"); background-size: cover; background-repeat: no-repeat; background-position: center center; } @media (max-width: 766px) { section { width: 90%; } col { width: 80%; margin: 10px auto; padding: 0; } .col.col-6 { width: 98%; min-height: 141px; margin-left: 0; margin-right: 0; } .col.col-6-bg { width: 98%; min-height: 200px; margin-left: 1%; margin-right: 1%; } } <h2>div img</h2> <div class="row"> <div class="col col-6"> <img class="img-responsive" src="http://prasinostcharles.com/wp-content/uploads/2014/09/gallery-large_food_cod.jpg"> </div> <div class="col col-6"> <img class="img-responsive" src="http://prasinostcharles.com/wp-content/uploads/2014/09/gallery-large_food_cod.jpg"> </div> </div> <h2> div img bacground</h2> <div class="col col-6-bg img-bg"></div> <div class="col col-6-bg img-bg"></div>
Comments
Post a Comment