Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
118 views
in Technique[技术] by (71.8m points)

html - Positioning divs on row and column on breakpoint

I have footer which contains two divs and I want them center and side by side. On breakpoint (960px) I want second div move below first one but still stay centered. Does anybody have idea how to do that?

Here is my code:

.content {
  width: 100%;
  display: flex;
  justify-content: center;
}

.contentWrapper {
  display: flex;
}

.contentItem {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 260px;
  box-sizing: border-box;
}

@media (max-width: 960px) {
  .contentWrapper {
    flex-direction: column;
  }
}
<div class='content'>
  <div class='contentWrapper'>
    <div class='contentItem'>
      <p>Name</p>
      <p>Address</p>
      <p>Email</p>
      <p>Phone</p>
    </div>
    <div class='contentItem'>
      <p>Name</p>
      <p>Address</p>
      <p>Email</p>
      <p>Phone</p>
    </div>
  </div>
</div>
question from:https://stackoverflow.com/questions/65952254/positioning-divs-on-row-and-column-on-breakpoint

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

HTML

<div class = 'content' > 
  <div class = 'contentWrapper' > 
   <div class = 'contentItem' > 
    <p> Nam1e </p>
    <p> Address </p> 
    <p> Email </p>
    <p> Phone </p>
   </div> 
   <div class = 'contentItem' > 
    <p> Name </p> 
    <p> Address </p> 
    <p> Email </p> 
    <p> Phone </p>
   </div> 
  </div> 
 </div>

CSS

 <style> 
  .content { display : flex ; justify-content : center ; }
  .contentWrapper { display : flex ; } 
  .contentItem { display : flex ; flex-direction : column ; align-items : center ; box-sizing : border-box ; } 
  @media ( max-width : 960px ) 
   { .contentWrapper 
    { flex-direction : column ; /* flex-direction: column-reverse; you can use this 
    for reverse (div-2 above and div-1 below) */ 
    } 
   } 
</style>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...