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

html - How to have two items on opposite sides on the same line

I'm trying to get two different pieces of text on opposite ends of the "page" so to speak for a mobile app.

I would like it to look like this:

|-----------------------------|
|DATE                  MESSAGE|

But on the same line.

Currently I've got it setup like this:

<div id="HASH" class="blue-msg">
<span id="time-HASH" class="smalltext">9 months 2 weeks ago</span>
<span class="ios-circle">MESSAGE HERE</span>
</div>

With the ios-circle span having display: inline-block set.

MESSAGE can also go on for multiple lines (like an iOS chat window), like so:

|-----------------------------|
|DATE                  MESSAGE|
|                      MESSAGE|

I don't care if the DATE text is aligned near the top of the message or near the center of the message. Either would look fine to me.

How do I do this? I would very much prefer to not use a float if possible.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Use flexbox, like this

#HASH {
  display: flex;
  justify-content: space-between;
}

P.S.: If the "MESSAGE HERE" content is supposed to expand across multiple lines, I would put it in a div (instead of span) and restrict its width to 50% (adjust value as you like).

#HASH {
  display: flex;
  justify-content: space-between;
}
<div id="HASH" class="blue-msg">
<span id="time-HASH" class="smalltext">9 months 2 weeks ago</span>
<span class="ios-circle">MESSAGE HERE</span>
</div>

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

...