htmlcss

How does one make two divs both take up 50% of the screen while maintaining their height responsively?


    

.card--card.gradient, .card__inner.gradient {
        transform: perspective(0);
    }
    .card--card, .card--standard .card__inner {
        position: relative;
        box-sizing: border-box;
    }
    .card__inner {
        width: 100%;
        display: flex;
        flex-direction: column;
        flex: 1 1 50%;
        overflow: hidden;
        --ratio-percent: 99.77064220183487%;
    }
    .ratio {
        display: flex;
        position: relative;
        align-items: stretch;
    }
    .gradient {
        background: #FFFCF2;
        background-attachment: fixed;
    }
    .card {
        text-decoration: none;
        height: 100%;
    }
    .card-wrapper {
        color: inherit;
        height: 100%;
        position: relative;
        text-decoration: none;
    }
    .grid {
        display: flex;
        flex-wrap: wrap;
        margin-bottom: 2rem;
        padding: 0;
        list-style: none;
    }
    ul {
        list-style-type: disc;
    }
   
   .ratio::before {
        content: '';
        width: 0;
        height: 0;
        padding-bottom: var(--ratio-percent);
    }
    .card--card:after, .card--standard .card__inner:after {
        content: "";
        position: absolute;
        z-index: -1;
    }
    .card .card__inner .card__media {
        overflow: hidden;
        z-index: 0;
        border-radius: calc(var(--border-radius) - var(--border-width) - var(--image-padding));
    }

    
    .card__media, .card .media {
        bottom: 0;
        position: absolute;
        top: 0;
        overflow: none;
    }
    
    slider-component {
        position: relative;
        display: block;
    }
    @media screen and (min-width: 750px) {
        body {
            font-size: 1.6rem;
        }
    }
    body {
        display: grid;
        grid-template-rows: auto auto 1fr auto;
        grid-template-columns: 100%;
        min-height: 100%;
        margin: 0;
        font-size: 1.5rem;
        letter-spacing: 0.06rem;
    }
    *, *::before, *::after {
        box-sizing: inherit;
    }

    .card--media .card__inner .card__content {
        position: relative;
        padding: calc(var(--image-padding) + 1rem);
    }

    .card__content {
        display: grid;
        grid-template-rows: minmax(0, 1fr) max-content minmax(0, 1fr);
        padding: 1rem;
        width: 100%;
        background-color: #dd6a33;
        flex: 1;
        height: 50%;
    }
    div {
        display: block;
        unicode-bidi: isolate;
    }
    .grid {
        display: flex;
        flex-wrap: wrap;
        margin-bottom: 2rem;
        padding: 0;
        list-style: none;
    }
    slider-component {
        position: relative;
        display: block;
    }
    @media screen and (min-width: 750px) {
        body {
            font-size: 1.6rem;
        }
    }
    body {
        display: grid;
        grid-template-rows: auto auto 1fr auto;
        grid-template-columns: 100%;
        min-height: 100%;
        margin: 0;
        font-size: 1.5rem;
        letter-spacing: 0.06rem;
    }    
    html {
        box-sizing: border-box;
        height: 100%;
    }
    <div class="card__inner color-scheme-2 gradient ratio" style="--ratio-percent: 99.77064220183487%;"><div class="card__media">
                <div class="media media--transparent media--hover-effect">
                  
                  <img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg" class="motion-reduce" loading="lazy" width="436" height="435">
                  
    </div>
              </div>
<div class="card__content">
              <div class="card__information">
                <h3 class="card__heading">
                  <a href="<link to other page>" id="StandardCardNoMediaLink-template--15500528386151__featured_collection_6iUf8K-7156043710567" class="full-unstyled-link" aria-labelledby="StandardCardNoMediaLink-template--15500528386151__featured_collection_6iUf8K-7156043710567 NoMediaStandardBadge-template--15500528386151__featured_collection_6iUf8K-7156043710567">
                    Link
                  </a>
                </h3>
              </div>
              <!---->
              <div class="card__badge bottom left"><span id="NoMediaStandardBadge-template--15500528386151__featured_collection_6iUf8K-7156043710567" class="badge badge--bottom-left color-scheme-3 view-product-span">
                    <!--Sold out-->
                   Text
                  </span></div>
            </div>
          </div>

I am trying to make the image container div, the div with the card__media class, and the div with the card__content class. I have been trying to mess with the styling through the inspect tool and look through StackOverflow. I tried to implement the first solution of this post by giving the top div (card__media class) flex: 0 1 auto, and the bottom div flex: 1 1 auto, but that didn't work. I tried making the height: 100% for the div with the card__content class as that class only took the size of the square area while the card_media div took the full height. A solution would be to make the card__content div take up the remaining area between the photo and the square, but I am stuck. Any help would be appreciated. Thank you. Also, I know the image does not fit the height and width as I just substituted an image I found to generalize the question.


Solution

  • Here is my snippet.

    Check this out.

     .mainDiv {
            height: 100vh;
            border: solid 2px red;
          }
          .gradiendDiv {
            height: 50%;
            border: solid 2px orange;
            background: linear-gradient(red, yellow);;
          }
          .imageDiv {
            height: 50%;
            border: solid 2px green;
            overflow: auto;
          }
    <div class="mainDiv">
          <div class="gradiendDiv"></div>
          <div class="imageDiv">
            <img
              src="http://www.gettyimages.ca/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg"
            />
          </div>
        </div>