Setting a max-width for flex items? [duplicate]

Mobile Technologies Mobile Computing 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating
_x000D_ _x000D_ _x000D_ This question already has an answer here:_x000D_ _x000D_ _x000D_ In CSS Flexbox, why are there no “justify-items” and “justify-self” properties?_x000D_ _x000D_ 5 answers_x000D_ _x000D_ _x000D_ _x000D_ _x000D_ I'm trying to create a filter section on my site, the content is all generated dynamically (so I can't add extra parents to it), and our styleguide creates them using flex items. I'd like to keep this functionality for the most part. I want my 3 flex items to have a max-width and be floated left, leaving my non flex item floated right, in the overall container that is set to a max width of 1080px sort of like this: Option 1 Option 2 Option 3 Non-flex Item I've tried setting the flex-align values and following this answer, but that doesn't seem to work for this. As of right now, this is the code that I am working with: HTML
  • One
  • Three
  • Three
  • I'm not a flex item
CSS .container{ display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-orient: horizontal; -webkit-box-direction: normal; -ms-flex-direction: row; flex-direction: row; -webkit-box-pack: justify; -ms-flex-pack: justify; justify-content: space-between; position: relative; max-width: 1080px; margin: 0 auto; padding: 0 20px; box-sizing: content-box; } .child{ display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-orient: horizontal; -webkit-box-direction: normal; -ms-flex-direction: row; flex-direction: row; -webkit-box-pack: justify; -ms-flex-pack: justify; justify-content: space-between; position: relative; } I also made a Fiddle for you all to play around.

Posted on 16 Aug 2022, this text provides information on Mobile Computing related to Mobile Technologies. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago
_x000D_ I would apply a width or min-width to the .child items (or left/right padding that creates the distance between them) and margin-left: auto to the last item, which moves it right, independently from the others: https://jsfiddle.net/6vwny6bz/2/ _x000D_ _x000D_ .container {_x000D_ display: -webkit-box;_x000D_ display: -ms-flexbox;_x000D_ display: flex;_x000D_ -webkit-box-orient: horizontal;_x000D_ -webkit-box-direction: normal;_x000D_ -ms-flex-direction: row;_x000D_ flex-direction: row;_x000D_ -webkit-box-pack: justify;_x000D_ -ms-flex-pack: justify;_x000D_ justify-content: space-between;_x000D_ position: relative;_x000D_ max-width: 1080px;_x000D_ margin: 0 auto;_x000D_ padding: 0 20px;_x000D_ box-sizing: content-box;_x000D_ }_x000D_ _x000D_ .child {_x000D_ list-style: none;_x000D_ min-width: 80px;_x000D_ padding: 10px 0;_x000D_ }_x000D_ _x000D_ .non-flex {_x000D_ margin-left: auto;_x000D_ padding: 10px 0;_x000D_ }_x000D_
    _x000D_
  • One
  • _x000D_
  • Three
  • _x000D_
  • Three
  • _x000D_
    _x000D_ I'm not a flex item_x000D_
    _x000D_
_x000D_ _x000D_

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Important Mobile Technologies Links