html - Center crop img to fill div -


i have 3 column holy grail layout width of left , right columns fixed , center column fluid. height of layout defined center column's contents. in right column need full bleed center cropped image. that's hard part. have sample of i'm going here i'm explicitly defining height of image 180px , i'd grow height of center column. also, i'd avoid using javascript if @ possible , not necessary use flexbox, that's best come far.

unless explicitly need use <img> tag use inline css styles control background-image of div rather placing element within div

for example:

<div class="container">     <div class="col1"></div>     <div class="col2">         lorem ipsum dolor sit amet, consectetur adipiscing elit. duis nec rhoncus orci, eget eleifend risus. maecenas suscipit arcu et aliquet tristique. quisque venenatis est maximus consectetur. nam id fringilla odio. mauris lobortis nec lorem nec congue. maecenas elit risus, vestibulum vitae quam eu, ultrices condimentum dolor. mauris magna nulla, congue eu enim a, fringilla cursus elit. nulla tempor finibus eleifend. class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.     </div>     <div class="col3">         <div class="fill" style="background-image:url('http://upload.wikimedia.org/wikipedia/commons/thumb/5/55/mona_lisa_headcrop.jpg/36px-mona_lisa_headcrop.jpg');">         </div>     </div> </div> 

then using css can control center'ed , fullness of image. note: assume css3 styles ok implementation given using flex-box

.container {     display: flex;     flex: 1; }  .col1 {     background-color: hotpink;     order: 0;     flex: 0 0 50px; }  .col2 {     background-color: deepskyblue;     order: 1;     flex: 1; }  .col3 {     background-color: hotpink;     order: 3;     flex: 0 0 70px;     position:relative; }  .fill {     position:absolute;     top:0;     left:0;     right:0;     bottom:0;     background-repeat:no-repeat;     background-size:cover;     background-position:center center; } 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -