Home > other >  How to make profile cards stack on mobile?
How to make profile cards stack on mobile?

Time:12-16

I have created profile cards, I need them to stack on top each other in pairs of 2 on mobile. Cards appear alongside each other on desktop, which is good, but mobile view needs adjustment. I need fitment compatible with all screen sizes.

Thank you in advance for any and all help, it is greatly appreciated. :)

    .card {
  box-shadow: 0 4px 8px 0 rgb(255, 255, 255);
  max-width: 350px;
  margin: auto;
  text-align: center;
  padding: 60px;
}

.title {
  color: rgb(255, 255, 255);
  font-size: 18px;
}

button {
  border: none;
  outline: 0;
  display: inline-block;
  padding: 8px;
  color: white;
  background-color: #000000;
  text-align: center;
  cursor: pointer;
  width: 100%;
  font-size: 18px;
}

a {
  text-decoration: none;
  font-size: 30px;
  color: rgb(255, 255, 255);
}

button:hover, a:hover {
  opacity: 0.7;
}

h1 {
  color:#ffffff;
  font-size: 32px;
}

.flex-container {
  display: flex;
}

.flex-child {
  flex: 1;
  border: 2px solid yellow;
}

.flex-child:first-child {
  margin-right: 20px;
}
     <div >
         <div >
      <div >
         <img src="img/Tee.png" alt="Tee" style="width:100%">
         <h1>Tristen</h1>
         <p >Founder</p>
         <a href="#"><i ></i></a>
         <p><button>Contact</button></p>
       </div>
      </div>
      <div >
       <div >
         <img src="img/Byrd.png" alt="Byrdman" style="width:100%">
         <h1>Landon</h1>
         <p >Founder</p>
         <a href="#"><i ></i></a>
         <p><button>Contact</button></p>
       </div>
      </div>
      </div>

CodePudding user response:

By default, a flexbox has a flex-direction: row;. you can set up a media query instructing the browser to change to flex-direction: column; for mobile screens.

.card {
  box-shadow: 0 4px 8px 0 rgb(255, 255, 255);
  max-width: 350px;
  margin: auto;
  text-align: center;
  padding: 60px;
}

.title {
  color: rgb(255, 255, 255);
  font-size: 18px;
}

button {
  border: none;
  outline: 0;
  display: inline-block;
  padding: 8px;
  color: white;
  background-color: #000000;
  text-align: center;
  cursor: pointer;
  width: 100%;
  font-size: 18px;
}

a {
  text-decoration: none;
  font-size: 30px;
  color: rgb(255, 255, 255);
}

button:hover, a:hover {
  opacity: 0.7;
}

h1 {
  color:#ffffff;
  font-size: 32px;
}

.flex-container {
  display: flex;
}

.flex-child {
  flex: 1;
  border: 2px solid yellow;
}

.flex-child:first-child {
  margin-right: 20px;
}

@media only screen and (max-width: 800px) {
  .flex-container {
    flex-direction: column;
  }
}
<div >
   <div >
      <div >
         <img src="img/Tee.png" alt="Tee" style="width:100%">
         <h1>Tristen</h1>
         <p >Founder</p>
         <a href="#"><i ></i></a>
         <p><button>Contact</button></p>
      </div>
   </div>
   <div >
      <div >
         <img src="img/Byrd.png" alt="Byrdman" style="width:100%">
         <h1>Landon</h1>
         <p >Founder</p>
         <a href="#"><i ></i></a>
         <p><button>Contact</button></p>
      </div>
   </div>
</div>

CodePudding user response:

Instead of

    .flex-container {
              display: flex;
            }

put

    @media only screen and (min-width: 600px) {
         .flex-container {
          display: flex;
        }
    }
    
    @media only screen and (max-width: 600px) {
         .flex-container {
          display: block;
        }
    }
  • Related