0

Considering the following card layout:

layout

@charset "UTF-8";
* {
  box-sizing: border-box;
}

body {
  background: #f1f1f1;
  margin: 2rem;
}

.card {
  border: 1px solid #000000;
}

.card-img {
  background-color: #000000;
}

.card {
  display: flex;
  margin: 1rem auto;
  background: #fff;
  font-family: Chivo, sans-serif;
  border-radius: 5px;
  overflow: hidden;
  z-index: 0;
  height: 150px;
  border: 1px solid #000000;
  flex-direction: row;
  max-width: 600px;
  width: 100%;
  cursor: pointer;
}

.card:hover {
  box-shadow: 3px 3px 0px 0px #222222;
  transition: box-shadow 0.3s ease-out;
}

.card .card-image-container {
  position: relative;
  z-index: 0;
  background-color: #000000;
  flex-basis: 150px;
  height: auto;
}

.card .card-image-content {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-size: cover;
  background-position: center;
  width: 160px;
}

.card .card-info-container {
  background: #fff;
  position: relative;
  z-index: 1;
  border-left: 1px solid #000000;
  display: flex;
  justify-content: space-between;
  flex-basis: 70%;
}

.card .card-info-container .card-info-title {
  line-height: 1;
  margin: 0;
  font-size: 1.1rem;
  position: absolute;
  top: 0;
  left: 0;
  padding: 10px;
}

.card-info-count {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 80px;
  padding: 10px;
  border-top: 1px solid #000000;
}

.card-info-price {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 80px;
  padding: 10px;
  border-top: 1px solid #000000;
  border-left: 1px solid #000000;
}
<div class="card">

  <div class="card-image-container">
    <div class="card-image-content" style="background-image: url(https://storage.googleapis.com/chydlx/codepen/blog-cards/image-1.jpg)"></div>
  </div>

  <div class="card-info-container">
    <div class="card-info-title">Lorem ipsum dolor sit amet, consectetur adipiscing elit</div>
    <div class="card-info-count">12 views</div>
    <div class="card-info-price">50 EUR</div>
  </div>

</div>

I would like to keep the image of a square size (in this case 150px), and have the card-info-container to fill the remaining of the card width. card-info-price should be always of 80px and card-info-count to fill the remaining width of card-info-container.

You can see on the bottom right that something is broken. What am I doing wrong?

cSharp
  • 2,884
  • 1
  • 6
  • 23

1 Answers1

2

What you need is flex-grow: 1 on the card-info-container:

@charset "UTF-8";
* {
  box-sizing: border-box;
}

body {
  background: #f1f1f1;
  margin: 2rem;
}

.card {
  border: 1px solid #000000;
}

.card-img {
  background-color: #000000;
}

.card {
  display: flex;
  margin: 1rem auto;
  background: #fff;
  font-family: Chivo, sans-serif;
  border-radius: 5px;
  overflow: hidden;
  z-index: 0;
  height: 150px;
  border: 1px solid #000000;
  flex-direction: row;
  max-width: 600px;
  width: 100%;
  cursor: pointer;
}

.card:hover {
  box-shadow: 3px 3px 0px 0px #222222;
  transition: box-shadow 0.3s ease-out;
}

.card .card-image-container {
  position: relative;
  z-index: 0;
  background-color: #000000;
  flex-basis: 150px;
  height: auto;
}

.card .card-image-content {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-size: cover;
  background-position: center;
  width: 160px;
}

.card .card-info-container {
  background: #fff;
  position: relative;
  z-index: 1;
  border-left: 1px solid #000000;
  display: flex;
  justify-content: space-between;
  flex-basis: 70%;
  flex-grow: 1;
}

.card .card-info-container .card-info-title {
  line-height: 1;
  margin: 0;
  font-size: 1.1rem;
  position: absolute;
  top: 0;
  left: 0;
  padding: 10px;
}

.card-info-count {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 80px;
  padding: 10px;
  border-top: 1px solid #000000;
}

.card-info-price {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 80px;
  padding: 10px;
  border-top: 1px solid #000000;
  border-left: 1px solid #000000;
}
<div class="card">

  <div class="card-image-container">
    <div class="card-image-content" style="background-image: url(https://storage.googleapis.com/chydlx/codepen/blog-cards/image-1.jpg)"></div>
  </div>

  <div class="card-info-container">
    <div class="card-info-title">Lorem ipsum dolor sit amet, consectetur adipiscing elit</div>
    <div class="card-info-count">12 views</div>
    <div class="card-info-price">50 EUR</div>
  </div>

</div>
Damzaky
  • 6,073
  • 2
  • 11
  • 16