Home > Software design >  Gap between card on mobile
Gap between card on mobile

Time:10-22

I have a very basic problem I tried to fix it for hours. I have made these cards using grid layout but on mobile, it doesn't have a gap between them. I need it to be at least 10px gap among them.

Image 01

It works fine on the desktop(but not centered). Image 02

Here's the code I'm using.

HTML:

<ul class="cards">
 
  <li>
    <div class="card">
      
      <img src="https://cdn.discordapp.com/attachments/888655046080872458/900257495333863444/unknown.png" class="card__image" alt="" />
      <div class="card__overlay">
        <div class="card__header">
          <svg class="card__arc" xmlns="http://www.w3.org/2000/svg"><path /></svg>                     
      
          <div class="card__header-text">
            <h3 class="card__title" >BALA KRISHNA</h3>            
            <span class="card__status">Game Architect</span>
          </div>
        </div>
        <p class="card__description">I drive the game here!</p>
      </div>
      </div>
    </a>      
  </li>
  <li>
    
    <div class="card">
      <img src="https://cdn.discordapp.com/attachments/888655046080872458/900257495333863444/unknown.png" class="card__image" alt="" />
      <div class="card__overlay">        
        <div class="card__header">
          <svg class="card__arc" xmlns="http://www.w3.org/2000/svg"><path /></svg>                 
         
          <div class="card__header-text">
            <h3 class="card__title">Prasanta Bhattacharya</h3>
            <span class="card__status">Game Developer</span>
          </div>
        </div>
        
        <p class="card__description">I make what you love!</p>
      </div>
    </a>
  </li>
  <li>

    <div class="card">
      <img src="https://cdn.discordapp.com/attachments/888655046080872458/900257495333863444/unknown.png" class="card__image" alt="" />
      <div class="card__overlay">
        <div class="card__header">
          <svg class="card__arc" xmlns="http://www.w3.org/2000/svg"><path /></svg>                 
  
          <div class="card__header-text">
            <h3 class="card__title">Myriam Roos</h3>
            <span class="card__status">Community Manager</span>
          </div>          
        </div>

        <p class="card__description">Lorem ipsum dolor sit amet consectetur adipisicing elit. Asperiores, blanditiis?</p>
      </div>
    </a>
  </li>    
  
  <li>
    <div class="card">
      <img src="https://cdn.discordapp.com/attachments/888655046080872458/900257495333863444/unknown.png" class="card__image" alt="" />
      <div class="card__overlay">
        <div class="card__header">
          <svg class="card__arc" xmlns="http://www.w3.org/2000/svg"><path /></svg>                 
  
          <div class="card__header-text">
            <h3 class="card__title">Alxsander</h3>
            <span class="card__status">Content Creator</span>
          </div>          
        </div>
        <p class="card__description">I create content here!</p>
      </div>
    </a>
  </li>    
</ul>
</div>

</div>

And CSS

* {
  box-sizing: border-box;
}


:root {
  --surface-color:black;
  --curve: 40;
}


.cards {
  display: grid;
  justify-content: center;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 10px 2rem;
  grid-row-gap: 5px;
  margin: 4rem 5vw;
  padding: 5;
  list-style-type: none;
  
 
  
}

.card {
  position: relative;
  display: block;
  height: 130%;  
  border-radius: calc(var(--curve) * 1px);
  overflow: hidden;
  text-decoration: none;
  border: solid;
  border-color: white;

  

}

.card__image {      
  width: 120%;
  height: auto;
}

.card__overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1;      
  border-radius: calc(var(--curve) * 1px);    
  background-color: var(--surface-color);      
  transform: translateY(100%);
  transition: .2s ease-in-out;
}

.card:hover .card__overlay {
  transform: translateY(0);
}

.card__header {
  position: relative;
  display: flex;
  align-items: center;
  gap: 2em;
  padding: 2em;
  border-radius: calc(var(--curve) * 1px) 0 0 0;    
  background-color: var(--surface-color);
  transform: translateY(-100%);
  transition: .2s ease-in-out;
}

.card__arc {
  width: 80px;
  height: 80px;
  position: absolute;
  bottom: 100%;
  right: 0;      
  z-index: 1;
}

.card__arc path {
  fill: var(--surface-color);
  d: path("M 40 80 c 22 0 40 -22 40 -40 v 40 Z");
}       

.card:hover .card__header {
  transform: translateY(0);
}

.card__thumb {
  flex-shrink: 0;
  width: 50px;
  height: 50px;      
  border-radius: 50%;      
}

.card__title {
  font-size: 1em;
  margin: 0 0 .3em;
  color: #6A515E;
}

.card__tagline {
  display: block;
  margin: 1em 0;
  font-size: .8em; 
  color: #D7BDCA;  
}

.card__status {
  font-size: .8em;
  color: #D7BDCA;
}

.card__description {
  padding: 0 2em 2em;
  margin: 0;
  color: #D7BDCA;

  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}    

I'm a noob in web design so please help! And of course, sorry for bad English :D

CodePudding user response:

Just changing your row-gap fixes that. Here I used

 grid-row-gap: 100px;

in .cards css.

Adjust to suit your needs.

MDN

* {
  box-sizing: border-box;
}

:root {
  --surface-color: black;
  --curve: 40;
}

.cards {
  display: grid;
  justify-content: center;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  grid-row-gap: 100px;  /* <----------------------------Changed to 100px */
  margin: 4rem 5vw;
  padding: 5;
  list-style-type: none;
}

.card {
  position: relative;
  display: block;
  height: 130%;
  border-radius: calc(var(--curve) * 1px);
  overflow: hidden;
  text-decoration: none;
  border: solid;
  border-color: white;
}

.card__image {
  width: 120%;
  height: auto;
}

.card__overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1;
  border-radius: calc(var(--curve) * 1px);
  background-color: var(--surface-color);
  transform: translateY(100%);
  transition: .2s ease-in-out;
}

.card:hover .card__overlay {
  transform: translateY(0);
}

.card__header {
  position: relative;
  display: flex;
  align-items: center;
  gap: 2em;
  padding: 2em;
  border-radius: calc(var(--curve) * 1px) 0 0 0;
  background-color: var(--surface-color);
  transform: translateY(-100%);
  transition: .2s ease-in-out;
}

.card__arc {
  width: 80px;
  height: 80px;
  position: absolute;
  bottom: 100%;
  right: 0;
  z-index: 1;
}

.card__arc path {
  fill: var(--surface-color);
  d: path("M 40 80 c 22 0 40 -22 40 -40 v 40 Z");
}

.card:hover .card__header {
  transform: translateY(0);
}

.card__thumb {
  flex-shrink: 0;
  width: 50px;
  height: 50px;
  border-radius: 50%;
}

.card__title {
  font-size: 1em;
  margin: 0 0 .3em;
  color: #6A515E;
}

.card__tagline {
  display: block;
  margin: 1em 0;
  font-size: .8em;
  color: #D7BDCA;
}

.card__status {
  font-size: .8em;
  color: #D7BDCA;
}

.card__description {
  padding: 0 2em 2em;
  margin: 0;
  color: #D7BDCA;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}
<ul class="cards">

  <li>
    <div class="card">

      <img src="https://cdn.discordapp.com/attachments/888655046080872458/900257495333863444/unknown.png" class="card__image" alt="" />
      <div class="card__overlay">
        <div class="card__header">
          <svg class="card__arc" xmlns="http://www.w3.org/2000/svg"><path /></svg>

          <div class="card__header-text">
            <h3 class="card__title">BALA KRISHNA</h3>
            <span class="card__status">Game Architect</span>
          </div>
        </div>
        <p class="card__description">I drive the game here!</p>
      </div>
    </div>
    </a>
  </li>
  <li>

    <div class="card">
      <img src="https://cdn.discordapp.com/attachments/888655046080872458/900257495333863444/unknown.png" class="card__image" alt="" />
      <div class="card__overlay">
        <div class="card__header">
          <svg class="card__arc" xmlns="http://www.w3.org/2000/svg"><path /></svg>

          <div class="card__header-text">
            <h3 class="card__title">Prasanta Bhattacharya</h3>
            <span class="card__status">Game Developer</span>
          </div>
        </div>

        <p class="card__description">I make what you love!</p>
      </div>
      </a>
  </li>
  <li>

    <div class="card">
      <img src="https://cdn.discordapp.com/attachments/888655046080872458/900257495333863444/unknown.png" class="card__image" alt="" />
      <div class="card__overlay">
        <div class="card__header">
          <svg class="card__arc" xmlns="http://www.w3.org/2000/svg"><path /></svg>

          <div class="card__header-text">
            <h3 class="card__title">Myriam Roos</h3>
            <span class="card__status">Community Manager</span>
          </div>
        </div>

        <p class="card__description">Lorem ipsum dolor sit amet consectetur adipisicing elit. Asperiores, blanditiis?</p>
      </div>
      </a>
  </li>

  <li>
    <div class="card">
      <img src="https://cdn.discordapp.com/attachments/888655046080872458/900257495333863444/unknown.png" class="card__image" alt="" />
      <div class="card__overlay">
        <div class="card__header">
          <svg class="card__arc" xmlns="http://www.w3.org/2000/svg"><path /></svg>

          <div class="card__header-text">
            <h3 class="card__title">Mr. Unity Buddy</h3>
            <span class="card__status">Content Creator</span>
          </div>
        </div>
        <p class="card__description">I create content here!</p>
      </div>
      </a>
  </li>
</ul>
</div>

</div>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

You destroyed the vertical gap by setting .card { height: 130%; }. Also the image width of 120% has no sense. Better add some bottom padding, or use flex instead. With padding it may look like this:

* {
  box-sizing: border-box;
}

:root {
  --surface-color: black;
  --curve: 40;
}

.cards {
  display: grid;
  justify-content: center;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 10px 2rem;
  grid-row-gap: 5px;
  margin: 4rem 5vw;
  padding: 5;
  list-style-type: none;



}

.card {
  position: relative;
  display: block;
  padding-bottom: 50px;
  border-radius: calc(var(--curve) * 1px);
  overflow: hidden;
  text-decoration: none;
  border: solid;
  border-color: white;
}

.card__image {
  width: 100%;
  height: auto;
}

.card__overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1;
  border-radius: calc(var(--curve) * 1px);
  background-color: var(--surface-color);
  transform: translateY(100%);
  transition: .2s ease-in-out;
}

.card:hover .card__overlay {
  transform: translateY(0);
}

.card__header {
  position: relative;
  display: flex;
  align-items: center;
  gap: 2em;
  padding: 2em;
  border-radius: calc(var(--curve) * 1px) 0 0 0;
  background-color: var(--surface-color);
  transform: translateY(-100%);
  transition: .2s ease-in-out;
}

.card__arc {
  width: 80px;
  height: 80px;
  position: absolute;
  bottom: 100%;
  right: 0;
  z-index: 1;
}

.card__arc path {
  fill: var(--surface-color);
  d: path("M 40 80 c 22 0 40 -22 40 -40 v 40 Z");
}

.card:hover .card__header {
  transform: translateY(0);
}

.card__thumb {
  flex-shrink: 0;
  width: 50px;
  height: 50px;
  border-radius: 50%;
}

.card__title {
  font-size: 1em;
  margin: 0 0 .3em;
  color: #6A515E;
}

.card__tagline {
  display: block;
  margin: 1em 0;
  font-size: .8em;
  color: #D7BDCA;
}

.card__status {
  font-size: .8em;
  color: #D7BDCA;
}

.card__description {
  padding: 0 2em 2em;
  margin: 0;
  color: #D7BDCA;

  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}
<ul class="cards">

  <li>
    <div class="card">

      <img src="https://cdn.discordapp.com/attachments/888655046080872458/900257495333863444/unknown.png" class="card__image" alt="" />
      <div class="card__overlay">
        <div class="card__header">
          <svg class="card__arc" xmlns="http://www.w3.org/2000/svg">
            <path /></svg>

          <div class="card__header-text">
            <h3 class="card__title">BALA KRISHNA</h3>
            <span class="card__status">Game Architect</span>
          </div>
        </div>
        <p class="card__description">I drive the game here!</p>
      </div>
    </div>
  </li>
  <li>

    <div class="card">
      <img src="https://cdn.discordapp.com/attachments/888655046080872458/900257495333863444/unknown.png" class="card__image" alt="" />
      <div class="card__overlay">
        <div class="card__header">
          <svg class="card__arc" xmlns="http://www.w3.org/2000/svg">
            <path /></svg>

          <div class="card__header-text">
            <h3 class="card__title">Prasanta Bhattacharya</h3>
            <span class="card__status">Game Developer</span>
          </div>
        </div>

        <p class="card__description">I make what you love!</p>
      </div>
    </div>
  </li>
  <li>

    <div class="card">
      <img src="https://cdn.discordapp.com/attachments/888655046080872458/900257495333863444/unknown.png" class="card__image" alt="" />
      <div class="card__overlay">
        <div class="card__header">
          <svg class="card__arc" xmlns="http://www.w3.org/2000/svg">
            <path /></svg>

          <div class="card__header-text">
            <h3 class="card__title">Myriam Roos</h3>
            <span class="card__status">Community Manager</span>
          </div>
        </div>

        <p class="card__description">Lorem ipsum dolor sit amet consectetur adipisicing elit. Asperiores, blanditiis?</p>
      </div>
    </div>
  </li>

  <li>
    <div class="card">
      <img src="https://cdn.discordapp.com/attachments/888655046080872458/900257495333863444/unknown.png" class="card__image" alt="" />
      <div class="card__overlay">
        <div class="card__header">
          <svg class="card__arc" xmlns="http://www.w3.org/2000/svg">
            <path /></svg>

          <div class="card__header-text">
            <h3 class="card__title">Alxsander</h3>
            <span class="card__status">Content Creator</span>
          </div>
        </div>
        <p class="card__description">I create content here!</p>
      </div>
    </div>
  </li>
</ul>
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

Also on JS Fiddle.

  • Related