1

From what I understand, flexbox is used to align multiple items in a container. If there is only a single item/child inside a container, is it best practice to still use flexbox? For example:

.container .child {
     display: flex;
     align-items: center;
}

In the example above, there is only one child. Of course, it will still display correctly, but I'm not sure if it's ideal.

If it isn't, what's the ideal way to go about it?

Pang
  • 9,564
  • 146
  • 81
  • 122
J Bo
  • 109
  • 3
  • Flex layout provides you with greater flexibility than older methods (e.g., floats, tables, positioning) in terms of the alignment of flex items. It doesn't matter if you have one item or 1000. The idea is you have access to flex properties and the broad range of options they provide. Creating a flex container for one item may be overkill, or it may not, depending on what you want to do and whether or not more items may one day be added. For more details, see [**here**](http://stackoverflow.com/q/32551291/3597276) and [**here**](https://css-tricks.com/snippets/css/a-guide-to-flexbox/). – Michael Benjamin Nov 01 '16 at 01:44
  • Depends what you want to achieve. Unless a perfect horisontal AND vertical position is needed, you might consider using other properties, simply because `flex` has next to no compatibility with older browsers, which might or might not play a rolw. – junkfoodjunkie Nov 01 '16 at 01:49
  • honestly, it is so convenient to center things uniformly it really doesn't matter; you can also use a flexbox shiv for older browsers – vladdobra Nov 01 '16 at 01:54
  • @Michael_B Sorry for the not being detailed, but scalability isn't an issue here. I won't be adding more than one child to the container so I thought it may be overkill, no? – J Bo Nov 01 '16 at 02:02
  • @vladdobra Right, the use of flexbox is really convenient. Uniformity isn't an issue here since there's only a single child and there won't be any children added ever. So I wasn't sure if flexbox would be the ideal choice or if it's better to other properties. – J Bo Nov 01 '16 at 02:06
  • This question is either too broad, opinion based or requires discussion and so is off-topic for Stack Overflow. If you have a specific, answerable, programming issue, please provide full details. – Paulie_D Nov 01 '16 at 11:31

0 Answers0