html - Flexbox - Horizontal component with full height squared image -
i try achieve seems easy task flexbox, after hours, fail...
i want create responsive horizontal component an image on left 100% height , flexible width text on right.
should easy, image never stops overlapping in best case...
body { font-family: sans-serif; } .card { background: #f1f1f2; display: flex; } .card-img { border: 1px solid green; } img { display: block; height: 100%; width: auto; } .card-body { flex: 1 1 auto; display: flex; flex-direction: column; justify-content: space-between; border: 1px solid blue; } <div class="card"> <div class="card-img"> <img src="http://placehold.it/100x100" alt="card image"> </div> <div class="card-body"> <h4 class="card-title">card title</h4> <p class="card-text">some amazing content lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> </div> </div>
in case, impossiple make right div have same height image because:
height of right div depend on it's witdh. because of parent div has fixed width width of right div depend on left div's width. left div width depend on image height. when change image height, right div height change too. now, think best way give image fixed size.
body { font-family: sans-serif; } .card { background: #f1f1f2; display: flex; } .card-img { border: 1px solid green; } img { display: block; height: 130px; width: auto; } .card-body { flex: 1 1 auto; display: flex; flex-direction: column; justify-content: space-between; border: 1px solid blue; } <div class="card"> <div class="card-img"> <img src="http://placehold.it/100x100" alt="card image"> </div> <div class="card-body"> <h4 class="card-title">card title</h4> <p class="card-text">some amazing content lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> </div> </div>
Comments
Post a Comment