html - How do you keep images (of varying size) inline with text? -


i'm working on bootstrap website , want make mobile version first. i'm trying keep images (on left) inline text (on right). i've managed pretty square pictures (1:1 aspect ratio) try different size distorted. here's example of code.

<div class="container"> <div class="row">     <div class="col-xs-4">         <img src="image.jpg" class="img-responsive">        </div>      <div class="col-xs-8">             <ul class="list-unstyled invinfo">                 <li class="heading"><h5>main title of page</h5></li>                 <li>some details page</li>                 <li>more details</li>             </ul>         </div> </div> </div>  

the best way describe i'm looking make amazons mobile app (the results when search something).

i start this, setting fixed width image , let text decided height.

for convenience added inline style background-image, content can handled in markup.

the great doing doesn't matter if image high/narrow or low/wide, still scale , keep ratio.

.container {    display: table;  }  .row {    display: table-row;  }  .cell {    display: table-cell;    border: 1px solid #ccc;    vertical-align: top;    height: 140px;  }  .cell.image {    width: 140px;    height: auto;    background-position: center center;    background-repeat: no-repeat;    background-size: contain;   }  .cell.image img {    max-width: 100%;    width: auto;    height: 100%;  }
<div class="container">    <div class="row">      <div class="cell image" style="background-image: url('http://placekitten.com/450/300')">            </div>      <div class="cell text">        <ul class="list-unstyled invinfo">          <li class="heading"><h5>main title of page</h5></li>          <li>some details page</li>          <li>more details</li>        </ul>          </div>    </div>    <div class="row">      <div class="cell image" style="background-image: url('http://placekitten.com/300/450')">            </div>      <div class="cell text">        <ul class="list-unstyled invinfo">          <li class="heading"><h5>main title of page</h5></li>          <li>some details page</li>          <li>more details</li>        </ul>          </div>    </div>    </div>


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -