Search code examples
htmlcsscss-grid

How can i have view upper side if i am writing code in down side


This is my HTML and CSS. I want a result like the image posted below. I have the number 1 on the top, and 2 on the bottom according to my code, but without changing the HTML, I want to have the result show 2 on the top and 1 on the bottom. I am trying to use CSS grid of bootstrap.

<style>
    .grid-container {
      grid-template-columns: footer header;
      grid-gap: 10px;
      background-color: #2196F3;
      padding: 10px;
    }
    .item1 { grid-area: footer; }
    .item2 { grid-area: header; }
    
.grid-container > div {
  background-color: rgba(255, 255, 255, 0.8);
  text-align: center;
  padding: 20px 0;
  font-size: 30px;
}
</style>   

 <div class="grid-container">
      <div class="item1">1</div>
      <div class="item2">2</div>
 </div>

result -:

this is the result showing me

but i want the result

require this result

HTML should not be changed. I want change in only CSS.


Solution

  • You can achieve this by using flex-wrap:wrap-reverse.

    .grid-container {
      grid-template-columns: footer header;
      grid-gap: 10px;
      background-color: #2196F3;
      padding: 10px;
      flex-wrap: wrap-reverse;
      display: flex;
      width:calc(100% - 20px);
    }
    
    .item1 {
      grid-area: footer;
    }
    
    .item2 {
      grid-area: header;
    }
    
    .grid-container>div {
      background-color: rgba(255, 255, 255, 0.8);
      text-align: center;
      padding: 20px 0;
      font-size: 30px;
      flex-basis: 100%;
    }
    <div class="grid-container">
      <div class="item1">1</div>
      <div class="item2">2</div>
    </div>