Home > Blockchain >  Need help fitting 4 columns into div - need to stretch the columns to fit copy
Need help fitting 4 columns into div - need to stretch the columns to fit copy

Time:02-24

I am attempting to fit 4 columns into a full width block on the page.

Right now 2 of the columns keep dropping below, so instead of being 4 across its 2 top and 2 bottom. This code works great for a 2 column layout but not a 4 column. I'm struggling to get the 4 columns full width of the block with a little space in between the edges and each column. Mobile can stack them, that's fine, but for desktop i would really like to get these to be next to each other.

Any help would be appreciated.

Thank you!

Here is my code:

#title {
  text-align: center;
  color: white;
  font-size: 30px;
  text-transform: uppercase;
  margin-top: 100px;
}

.hover-table-layout {
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-flex-wrap: wrap;
  -moz-flex-wrap: wrap;
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
  max-width: 100vw;
  margin-left: auto;
  margin-right: auto;
  text-align: center;
}

.listing-item {
  display: contents;
  width: 50%;
  // max-height: fit-content;
  // max-width: fit-content;
  margin-bottom: 10px;
  float: left;
  position: relative;
  //left: 5.5%;
  background: #fff;
  border-radius: 10px;
  z-index: 0;
  margin: 5px;
  //overflow: auto;
  //width: fit-content
  //block-size: fit-content
  cursor: pointer;
  -webkit-transition: all 0.3s ease;
  -moz-transition: all 0.3s ease;
  transition: all 0.3s ease;
  //-webkit-box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.10);
  //-moz-box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.10);
  //box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.10);
}

.listing-item:hover,
.listing-item.active {
  -webkit-transform: scale(1.03);
  -moz-transform: scale(1.03);
  transform: scale(1.03);
  -webkit-transition: all 0.3s;
  -moz-transition: all 0.3s;
  transition: all 0.3s;
  z-index: 2;
}

.listing-item .listing {
  padding: 10px;
  position: relative;
}

.listing-item .listing:before {
  content: "";
  position: absolute;
  top: -15px;
  left: -o-calc(50% - 15px);
  left: -moz-calc(50% - 15px);
  left: -webkit-calc(50% - 15px);
  left: calc(50% - 15px);
  border-bottom: 20px solid #fff;
  border-left: 20px solid transparent;
  border-right: 20px solid transparent;
}

figure.image img {
  width: 100%;
  height: 100%;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}

figure.image {
  position: relative;
  margin: 0;
  padding: 0;
}

figure.image figcaption {
  position: absolute;
  top: 0;
  width: 100%;
  text-align: center;
  bottom: 0.1px;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}

figcaption .caption {
  position: relative;
  top: 50%;
  -moz-transform: translateY(-50%);
  -webkit-transform: translateY(-50%);
  transform: translateY(-50%);
  margin: auto;
}

figcaption h1 {
  color: white;
  font-weight: bold;
  font-size: 16px;
  text-transform: uppercase;
}

figcaption p {
  color: white;
  font-size: 12px;
}

.listing h4 {
  font-size: 13px;
  text-align: center;
  padding: 5px 10px;
  font-weight: bold;
}

.listing h4:not(:last-child) {
  border-bottom: 1px solid #ccc;
}

.listing-item:hover figure.image figcaption {
  background: rgba(232, 114, 17, 0.6);
}

@media only screen and (min-width:540px) {
  .listing-item {
    display: block;
    width: -webkit-calc(100%/3);
    width: -moz-calc(100%/3);
    width: calc(100%/3);
  }
}

@media only screen and (min-width:1024px) {
  .hover-table-layout {
    padding: 30px;
  }
}
<div  id="deals">
  <div  data-toggle="modal" data-target="#Modal">
    <figure >
      <img src="https://image.png" alt="image">
      <figcaption>
      </figcaption>
    </figure>
    <div >
      <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
      <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
      <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
      <<h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
        <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
        <h3 style="color:green;">copy</h3>
        <a  data-toggle="modal" data-target="#Modal">Yes! I Want This</a>
    </div>
  </div>

  <div  data-toggle="modal" data-target="#subscribeModal2">
    <figure >
      <img src="https://image.png" alt="image">
      <figcaption>
      </figcaption>
    </figure>
    <div >
      <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
      <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
      <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
      <<h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
        <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
        <h3 style="color:green;">copy</h3>
        <a  data-toggle="modal" data-target="#Modal">Yes! I Want This</a>
    </div>
  </div>


  <div  data-toggle="modal" data-target="#subscribeModal2">
    <figure >
      <img src="https://image.png" alt="image">
      <figcaption>
      </figcaption>
    </figure>
    <div >
      <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
      <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
      <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
      <<h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
        <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
        <h3 style="color:green;">copy</h3>
        <a  data-toggle="modal" data-target="#Modal">Yes! I Want This</a>
    </div>
  </div>


  <div  data-toggle="modal" data-target="#subscribeModal2">
    <figure >
      <img src="https://image.png" alt="image">
      <figcaption>
      </figcaption>
    </figure>
    <div >
      <div >
        <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
        <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
        <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
        <<h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
          <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
          <h3 style="color:green;">copy</h3>
          <a  data-toggle="modal" data-target="#Modal">Yes! I Want This</a>
      </div>
    </div>

  </div>

CodePudding user response:

Do this changes:

Removed these codes from .listing-item:

display: contents;
float: left;
position: relative;
margin: 5px;

Added padding: 5px to .listing-item and box-sizing: border-box to * for a distance between items.

In media-query removed display: block and width: calc(100% / 3) replaced with width: calc(100% / 4)

* {
  box-sizing: border-box;
}

#title {
  text-align: center;
  color: white;
  font-size: 30px;
  text-transform: uppercase;
  margin-top: 100px;
}

.hover-table-layout {
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-flex-wrap: wrap;
  -moz-flex-wrap: wrap;
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
  max-width: 100vw;
  margin-left: auto;
  margin-right: auto;
  text-align: center;
}

.listing-item {
  width: 50%;
  // max-height: fit-content;
  // max-width: fit-content;
  margin-bottom: 10px;
  padding: 5px;
  //left: 5.5%;
  background: #fff;
  border-radius: 10px;
  z-index: 0;
  //overflow: auto;
  //width: fit-content
  //block-size: fit-content
  cursor: pointer;
  -webkit-transition: all 0.3s ease;
  -moz-transition: all 0.3s ease;
  transition: all 0.3s ease;
  //-webkit-box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.10);
  //-moz-box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.10);
  //box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.10);
}

.listing-item:hover,
.listing-item.active {
  -webkit-transform: scale(1.03);
  -moz-transform: scale(1.03);
  transform: scale(1.03);
  -webkit-transition: all 0.3s;
  -moz-transition: all 0.3s;
  transition: all 0.3s;
  z-index: 2;
}

.listing-item .listing {
  padding: 10px;
  position: relative;
}

.listing-item .listing:before {
  content: "";
  position: absolute;
  top: -15px;
  left: -o-calc(50% - 15px);
  left: -moz-calc(50% - 15px);
  left: -webkit-calc(50% - 15px);
  left: calc(50% - 15px);
  border-bottom: 20px solid #fff;
  border-left: 20px solid transparent;
  border-right: 20px solid transparent;
}

figure.image img {
  width: 100%;
  height: 100%;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}

figure.image {
  position: relative;
  margin: 0;
  padding: 0;
}

figure.image figcaption {
  position: absolute;
  top: 0;
  width: 100%;
  text-align: center;
  bottom: 0.1px;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}

figcaption .caption {
  position: relative;
  top: 50%;
  -moz-transform: translateY(-50%);
  -webkit-transform: translateY(-50%);
  transform: translateY(-50%);
  margin: auto;
}

figcaption h1 {
  color: white;
  font-weight: bold;
  font-size: 16px;
  text-transform: uppercase;
}

figcaption p {
  color: white;
  font-size: 12px;
}

.listing h4 {
  font-size: 13px;
  text-align: center;
  padding: 5px 10px;
  font-weight: bold;
}

.listing h4:not(:last-child) {
  border-bottom: 1px solid #ccc;
}

.listing-item:hover figure.image figcaption {
  background: rgba(232, 114, 17, 0.6);
}

@media only screen and (min-width:540px) {
  .listing-item {
    width: -webkit-calc(100% / 4);
    width: -moz-calc(100%/4);
    width: calc(100% / 4);
  }
}

@media only screen and (min-width:1024px) {
  .hover-table-layout {
    padding: 30px;
  }
}
<div  id="deals">
  <div  data-toggle="modal" data-target="#Modal">
    <figure >
      <img src="https://image.png" alt="image">
      <figcaption>
      </figcaption>
    </figure>
    <div >
      <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
      <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
      <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
      <<h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
        <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
        <h3 style="color:green;">copy</h3>
        <a  data-toggle="modal" data-target="#Modal">Yes! I Want This</a>
    </div>
  </div>

  <div  data-toggle="modal" data-target="#subscribeModal2">
    <figure >
      <img src="https://image.png" alt="image">
      <figcaption>
      </figcaption>
    </figure>
    <div >
      <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
      <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
      <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
      <<h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
        <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
        <h3 style="color:green;">copy</h3>
        <a  data-toggle="modal" data-target="#Modal">Yes! I Want This</a>
    </div>
  </div>


  <div  data-toggle="modal" data-target="#subscribeModal2">
    <figure >
      <img src="https://image.png" alt="image">
      <figcaption>
      </figcaption>
    </figure>
    <div >
      <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
      <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
      <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
      <<h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
        <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
        <h3 style="color:green;">copy</h3>
        <a  data-toggle="modal" data-target="#Modal">Yes! I Want This</a>
    </div>
  </div>


  <div  data-toggle="modal" data-target="#subscribeModal2">
    <figure >
      <img src="https://image.png" alt="image">
      <figcaption>
      </figcaption>
    </figure>
    <div >
      <div >
        <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
        <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
        <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
        <<h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
          <h4 style="color:black;">title<br> <span style="color:red;"> copy</span></h4>
          <h3 style="color:green;">copy</h3>
          <a  data-toggle="modal" data-target="#Modal">Yes! I Want This</a>
      </div>
    </div>

  </div>

CodePudding user response:

Remove flex-wrap from your container (.hover-table-layout), this is what causes your content to wrap into two rows.

  • Related