0

Here's the my current code in jsfiddle:

<div class="card-container">
  <div class="float-layout">
    <div class="card-image">
      <img src="https://images.pexels.com/photos/534151/pexels-photo-534151.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260">
      <div class="card">
        <div class="card-title">Title</div>
        <div class="card-desc">
          Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce ullamcorper
          mollis tempus. Mauris eu maximus lectus, eu auctor justo. Aenean porta purus
          vel commodo consequat.
        </div>
      </div>
    </div>
  </div>
</div>
.float-layout {
  padding: 5px 5px;
  float: left;
  width: 100%;
  height: auto;
  box-sizing: border-box;
  margin: 0;
}

.card-container {
  overflow: hidden;
}

.card {
  background-color: dodgerblue;
  color: black;
  height: 100%;
  width: 50%;
  float: right;
}

.card-title {
  font-size: 30px;
  text-align: center;
  font-weight: bold;
  padding-top: 20px;
}

.card-desc {
  padding: 10px;
  text-align: left;
  font-size: 18px;
}

div.card-image img {
  width: 50%;
  height: auto;
}

/* Phone Devices Query */
@media only screen and (max-width: 37.5em) {
  div.card-image img {
    width: 100%;
    height: auto;
  }

  .card {
    width: 100%;
    margin-top: -4px;
  }
}

I am not sure if I need the clearfix hack to solve this, but when I adjust the browser window, the right side of my media card (contains title and description) does not properly scale with the left side where my image is set. I would like for both of them to responsively scale at equal height and size.

To get a better idea, my current code looks like this: https://i.stack.imgur.com/xebaE.png

I want it to scale at equal height, responsively like this as I adjust the browser window to any size: https://i.stack.imgur.com/IkXok.png

Ruben Helsloot
  • 12,582
  • 6
  • 26
  • 49
dev1791456
  • 23
  • 1
  • 2

1 Answers1

3

Was it necessary?

.float-layout {
  padding: 5px 5px;
  float: left;
  width: 100%;
  height: auto;
  box-sizing: border-box;
  margin: 0;
}

.card-container {
  overflow: hidden;
}

.card {
  background-color: dodgerblue;
  color: black;
  min-height: 100%; /*replace this it in width: 100%*/
  width: 50%;
  float: right;
}

.card-title {
  font-size: 30px;
  text-align: center;
  font-weight: bold;
  padding-top: 20px;
}

.card-desc {
  padding: 10px;
  text-align: left;
  font-size: 18px;
}

/*add this it*/
.card-image {
  display: flex;
}
/*-------------*/

div.card-image img {
  width: 50%;
  height: auto;
}

/* Phone Devices Query */
@media only screen and (max-width: 37.5em) {
  div.card-image img {
    width: 100%;
    height: auto;
  }
  
  /*add this it*/
  .card-image {
     flex-direction: column;
  }
  /*----------------------*/

  .card {
    width: 100%;
    margin-top: -4px;
  }
}
<div class="card-container">
  <div class="float-layout">
    <div class="card-image">
      <img src="https://images.pexels.com/photos/534151/pexels-photo-534151.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260">
      <div class="card">
        <div class="card-title">Title</div>
        <div class="card-desc">
          Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce ullamcorper
          mollis tempus. Mauris eu maximus lectus, eu auctor justo. Aenean porta purus
          vel commodo consequat.
        </div>
      </div>
    </div>
  </div>
</div>
s.kuznetsov
  • 14,870
  • 3
  • 10
  • 25
  • Thank you! That works perfectly. I tried clearfix, but it didn't work. This component was originally part of a different code base I made. I tried to change it to your solution, unsuccessfully. Most of my components share the same base code, with just a few minor changes. On a side note, how does this code rate compared to other solutions? – dev1791456 Aug 13 '20 at 22:03
  • Most likely you haven't used all of my code. In the css, I marked everything that I added and replaced. Try again. – s.kuznetsov Aug 13 '20 at 22:12
  • I said your solution worked. I meant that initially when I was working on changing it to how it's supposed to work (and how you solved it), that I was unsuccessful. You're solution is good, much appreciation. I didn't realize it was that simple. Combining float with flex seems to be a pretty simple and robust solution. – dev1791456 Aug 13 '20 at 22:20