I\'m trying to center inner elements of a -tag with flexbox\'s
justify-content: center
. But Safari does not center them. I can apply
In some browsers the In addition to See the bug reports below for more details. Note: Although they cannot be flex containers, There is a simple and easy cross-browser workaround to this problem: Wrap the content of the Adjusted HTML (wrapped
Test
Test
Adjusted CSS (targeted Revised Demo Flexbox on a User (Oriol Brufau): The children of the User (Daniel Holbert): That is effectively what the HTML spec requires. Several HTML container-elements are "special" and effectively ignore their CSS Add support for display:flex/grid and columnset layout inside User (Daniel Holbert): This isn't specific to flexbox -- e.g. we don't render scrollbars if you put Stepping back even further, this isn't specific to And old-timey HTML elements like Also see: element doesn't accept changes to its
display
value, beyond switching between block
and inline-block
. This means that a element cannot be a flex or grid container, or a
, either.
elements, you may find this constraint applying to
and
elements, as well.
elements can be flex items.
The Solution
button
in a span
, and make the span
the flex container.button
content in a span
)span
)button > span, p {
display: flex;
flex-direction: row;
justify-content: center;
}
References / Bug Reports
are blockified, as dictates the flexbox spec. However, the
seems to establish a block formatting context instead of a flex one.
display
value in Gecko [aside from whether it's inline-level vs. block-level]. is one of these.
&
are as well.
is not implementable (by browsers) in pure CSS, so they are a bit of a black box, from the perspective of CSS. This means that
they don't necessarily react in the same way that e.g. a
overflow:scroll
on a button, and we don't render it as a
table if you put display:table
on it.. Consider
and
which also have special rendering
behavior.
and
and
simply do not support custom
display
values, other than
for the purposes of answering the very high-level question of "is this
element block-level or inline-level", for flowing other content around
the element.