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

css - How to use flexbox to make two columns of same width?

I'm just starting my flexbox journey and have encountered the silliest problem: I can't figure out how to have two columns of equal width.

My markup looks like this:

<div class="flex-wrap">
  <div class="left-col"></div>
  <div class="right-col"></div>
</div>

and my css is

.flex-wrap {
  display: flex;
  flex: 2 1 auto;
}

They start out equal width, and responsively remain the same width UNTIL a certain point at which the content of left begins to push it larger.

How can I assure they stay the same width?

question from:https://stackoverflow.com/questions/66054289/how-to-use-flexbox-to-make-two-columns-of-same-width

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

1 Reply

0 votes
by (71.8m points)

Use flex properties like so.

.flex-wrap {
  display: flex;
}

.flex-wrap div {
  flex: 1 0 50%;
  border: 1px solid red;
}
<div class="flex-wrap">
  <div class="left-col">Lorem ipsum dolor sit, amet consectetur adipisicing elit. Dolores aliquid suscipit, id perferendis quos at assumenda repellat libero itaque obcaecati velit sunt asperiores non nisi.</div>
  <div class="right-col">Lorem ipsum dolor sit amet.</div>
</div>

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

...