Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

flexbox - Match outer divs width to the max width of inner div with CSS and flex layout

How can I limit an outer element to shrink to the size of the inner one with css?

I have created a fiddle to reflect the problem I am experiencing a bit better:

https://jsfiddle.net/Holger50/4tx7smeb/

.holder {
  display: flex;
  }

.left {
  flex: 3;
  max-width: 500px;
  /*display:inline-block;*/
  }

.right {
  flex: 1;
  }

.someInnerContentWithWidth {
  width: 400px;
  }

<div class='holder'>
  <div class='left'>
    <div class='someInnerContentWithWidth'>
      Content with fixed width
    </div>
  </div>
  <div class='right'>
    This should take up the rest of the space
  </div>
 </div>

The right div should have all remaining space that is not used by the blue area (that has a fixed width)

The first box works as expected, it takes over the maximum amount of space and after it reaches max-width, the right div takes the rest. Fine so far but how can I have the outer left div to max-width the inner blue content area? The blue area cannot extent any further and needs to stay with that width.

The use of "display:inline-block;" is not working properly as the flex layout predicts the outer width. Likely there is some easy solution to it.


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

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...