How to keep responsive images same height?

后端 未结 3 1843
时光说笑
时光说笑 2021-01-02 21:55

I have a webpage that I\'m making, and I have one row with a cover photo and profile picture side-by side. I have them both in a bootstrap row in different-sized grids. But,

相关标签:
3条回答
  • 2021-01-02 22:08

    None of the above worked for me, but this did:

    HTML

    <div class="row cover-row">
    <div class="col-sm-8">
        <img src="http://placehold.it/851x315" class="img-responsive" alt="Cover Photo">
    </div>
    <div class="col-sm-4 profile-wrap">
        <img src="http://placehold.it/200x200" class="img-responsive profile-pic" alt="Profile Picture">
    </div>
    

    CSS

    .profile-pic {
        width: 100%; /* maintain width/height aspect ratio */
        height: 500px; /*I realized this doesnt seem responsive, but no percentages work for me but it appears fine on mobile*/
    }
    
    0 讨论(0)
  • 2021-01-02 22:13

    use min-height on them

    try

    img {
    min-height:100%
    }
    

    if that doesn't work use a fixed max-height

    img {
    min-height:4em;
    }
    
    0 讨论(0)
  • 2021-01-02 22:19

    You can use following codes.

    HTML

    <div class="row cover-row">
        <div class="col-sm-8">
            <img src="http://placehold.it/851x315" class="img-responsive" alt="Cover Photo">
        </div>
        <div class="col-sm-4 profile-wrap">
            <img src="http://placehold.it/200x200" class="img-responsive profile-pic" alt="Profile Picture">
        </div>
    </div>
    

    CSS

    /* Desktop and Tablet Screens */
    @media (min-width:768px) {
        .cover-row {
            position: relative;
            min-height: 100px; /* minimum height of cover stripe */
        }
        .profile-wrap {
            position: absolute;
            right: 0;
            top: 0;
            height: 100%;
            overflow: hidden;
        }
        .profile-pic {
            width: auto; /* maintain width/height aspect ratio */
            height: 100%;
        }
    }
    

    JSFiddle link http://jsfiddle.net/feh4ex3p/

    0 讨论(0)
提交回复
热议问题