网页 综合 更新时间 2026-10-29 07:30:00

Stack Layout · Sketch

自动蜘蛛 www.sketch.com 正文约 5970 字
Stack Layout · Sketch
With Stacks, you can create anything from buttons that grow or shrink to fit their labels, to entire interfaces with nested layouts that adapt to container size or content.
Stack layouts can grow or shrink based on their contents, and adapt their contents to stay within a fixed size or fill out their container. You can choose the direction of layouts, whether layers within a stack wrap or not, how they fill the available space, how they align, and more.
Although not a 1:1 equivalent of CSS Flexbox, stacks and their sizing options are very similar. We include relevant properties when you copy CSS from stack containers and their contents — both in the Mac app or the web app’s Inspect mode.
At their most basic level, stacks are frames with layout properties. You can add a stack to empty frames or groups, or create one from one or more layers.
There are a few different ways to create a stack:
Creating a Stack using the Inspector controls and adjusting its padding on the Canvas.
When you create a stack, we call its topmost frame the container, and everything inside it items.
In the Stack section of the Inspector, you’ll find all the options to control how your stack and items within it appear and adapt. Here’s what you can change:
Numbered controls correspond to the list below.
Additional stack settings controls whether your stack items’ outside and center borders are part of layout calculations, and also the order of overlapping items.
Direction can be vertical or horizontal. The vertical direction arranges layers in a column, and the horizontal direction in a row — great for things like lists or cards.
Wrap moves overlfowing content onto a new row or column. Wrap helps layouts adapt naturally as you resize, add, or remove elements.
Alignment, Cross-axis alignment, and Distribution defines how layers are positioned within a stack.
Spacing defines the distance between layers in a stack.
Padding defines how much space is between the stack edges and its contents.
Toggle individual padding switches between left/top/right/bottom padding fields and horizontal (left-right)/vertical (top-bottom) fields.
Pair padding values sets the same padding value for the horizontal and vertical padding fields.
You can override cross-axis alignment by selecting an individual stack item and selecting an alignment option at the top of the Inspector.
Control whether borders are included in layout calculations, and the stacking order of overlapping items.
Open the stack settings panel using the Stack settings button next to the Stack heading in the Inspector. Inside you’ll find:
Include borders in layout makes padding and gaps account for outside or centered borders that would otherwise eat into the spacing. The size fields in the Inspector still show a layer’s own size, not the size including borders add to it. Additionally, a relative layer with 100% height won’t visually fill the full height of the stack — it’ll be that minus the border(s).
Layering controls the order of overlapping stack items. Choose First on top (the default) or Last on top. This does not affect the order of layers in the Layer List.
You can also adjust padding on the Canvas by dragging on the handles that appear when you hover over a stack. What happens when you drag a handle depends on your Stack’s settings in the Inspector.
If you have toggled individual padding values, you can drag and set padding for each side’s handle individually. If you have paired horizontal and vertical values, dragging a handle on any side will affect all sides. For unpaired horizontal and vertical values, dragging the top handle will affect the bottom, and dragging the left handle will affect the right (and vice versa).
In this example we have a parent stack with its height set to fit (so adjusting the padding adjusts the overall dimensions) and a nested stack set to fixed (so adjusting the padding doesn’t affect its overall width).
These are stacks that are not inside another stack — but they can be inside frames, groups, or graphics.
You have the following options for a non-nested stack’s height and width:
Double-click the edge of a stack to change it from Fixed to Fit.
A non-nested stack set to Fit or Relative can also have a minimum and maximum size, just like a stack item.
By nesting stacks, you can create complex designs that mix directions and adapt to different sizes. Each nested stack has its own layout and sizing settings, giving you full control over item positioning, resizing behavior, and how content fills the available space.
You have the following options for a nested stack’s height and width:
In this example, the nested stack’s sizing starts as Fill (filling the height of its parent stack), we then switch it to Fit, and finally drag its container which switches it to fixed.
When you select a stack item or nested stack on the canvas, holding ⌥ and double-clicking on any edge will change that axis from Fixed or Fit to Fill.
A nested stack set to Fill, Fit, or Relative can also have a minimum and maximum size, just like any other stack item.
Stack items are the layers inside a stack: shapes, text, or even nested stacks. You can apply sizing options to these items to control how they resize within the stack.
There are three sizing options for a stack item’s height or width:
You cannot set a stack item to Fit, except text layers.
In this example, we show a stack item’s sizing being switched from Fixed to Fill (which fills the width of the stack), then to relative with its value set to 48% to match the width of other items in the stack.
Stack items, and non-nested stacks themselves, can have a minimum and maximum size on each axis without a fixed size. Toggle the Constrain Size button in the Layout section of the Inspector to reveal the min/max height and width fields below the sizing options.
Min/max sizing is only available on an axis that doesn’t already have a fixed size, and only supports absolute values, not percentages.
访问原文 返回搜索 https://www.sketch.com/docs/designing/stack-layout/
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。