Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centering Content in Flex 4

I'm building a custom component that extends SkinnableContainer. I can center the content either vertically or horizontally inside it, but not both-- and that is what I need.

I'm setting the layout to HorizontalLayout for the component and setting verticalAlign to middle.

Then I'm creating a canvas to surround another component that goes inside this component, and setting that canvas width to 100%, and then setting textAlign=center, but no dice.

Any help is appreciated.

like image 318
ruedaminute Avatar asked Nov 22 '09 18:11

ruedaminute


People also ask

How do I center vertically in Flex?

The align-items property (on the container) sets the default value of align-self (on the items). Therefore, align-items: center means all flex items will be set to align-self: center . But you can override this default by adjusting the align-self on individual items.

How do I align text in Flex?

Vertical align to center: The flexbox property is used to set the content to vertical align. The text content can be aligned vertically by setting the following display properties: align-items. justify-content.

How do I align content in center?

To just center the text inside an element, use text-align: center; This text is centered.


1 Answers

Use the horizontalCenter and verticalCenter properties to center your groups. The value is the number of pixels from either center where the sign of value denotes direction, 0 is absolute center.

This'll do the trick (assuming you want horizontal layout for your items). The 's' namespace refers to the spark components, since you're asking about flex 4 I assume Halo isn't of interest.

<s:Group>
    <!-- Any parent with BasicLayout will acknowledge horizontalCenter and verticalCenter -->
    <s:layout>
         <s:BasicLayout />
    </s:layout>

    <s:Group horizontalCenter="0" verticalCenter="0">
        <s:layout>
            <s:HorizontalLayout/>
        </s:layout>

        <s:Button />
        <s:Button />
        <s:Button />
    </s:Group>
</s:Group>
like image 123
Marcus Stade Avatar answered Oct 18 '22 20:10

Marcus Stade