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

Mobile Technologies Mobile Computing 3 years ago

9.79K 1 0 0 0

_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.

User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 3 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_
0 views
0 shares

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.

Similar Forum


Q

Would Firebase be a good choice as a server for the Flutter mobile game I'm creating?

_x000D_ _x000D_ I am building a turn-based Flutter game. Would Firebase be a good choice as a server...
Q

Implement Bottom Navigation activity along with a VerticalViewPager with nested Cardview in Android...

_x000D_ _x000D_ I want to develop an Android App which will have a Bottom Navigation Bar and above i...
Q

(JS) For , determine if the device offers or not to capture a photo from the camera

_x000D_ _x000D_ When uploading a file, I need to give the user the possibility: upload the file fr...

Important Mobile Technologies Links