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
191 views
in Technique[技术] by (71.8m points)

html - align divs left and right next to each other

I'm not sure if i'm doing this right.

Trying to align divs left and right on same line, But when i resize window the right div drops down and stays to the right.

How would i re align the divs so that when i make the window smaller the right drops down and lines up with left div, maybe centre both divs?

Do i need to add them into a grid list with <lu>?

Also how would i align the phone numbers up?

.text-center {
  text-align: center!important;
}

.text-left {
  text-align: left!important;
}

.text-right {
  text-align: right!important;
}

.right {
  float: right!important
}

.left {
  float: left!important
}
<div class="left">
  <h2>Infomation:</h2>
  <p>
    Phone: (00) 00000000<br/> Fax: (00) 00000000<br/> Email: <a href="mailto:[email protected] ">[email protected]<br/></a>
  </p>
</div>

<div class="right text-right">
  <h2>Business Hours:</h2>
  <p>
    Monday - Thursday<br/> 8:30 - 5:00<br/> Friday <br/> 8:30 - 3:30<br/>
  </p>
</div>
See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

I recommend using media queries for this. The logic is pretty simple. First, set the CSS rules for small screens. Then use a media query to apply new CSS rules for whenever the window is wider than a certain width.

.text-center {
  text-align: center!important;
}    
.text-left, .text-right {
  text-align: left!important;
}    
.left, .right {
  display: block;
}    
@media all and (min-width: 400px) {
  .left {
    float: left!important
  }
  .right {
    float: right!important
  }
  .text-right {
    text-align: right!important;
  }
}

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

...