Layout Gap from Target Width
Solve uniform inter-item gap for an exact target row width; preserve negative infeasibility instead of clamping.
Description
Solve uniform inter-item gap for an exact target row width; preserve negative infeasibility instead of clamping.
Equal gaps between equal-width items can be solved from a target width when at least two items are present.
When to use this tool
Solve uniform inter-item gap for an exact target row width; preserve negative infeasibility instead of clamping.
- Prepare the supplied targetWidth, itemWidth, itemCount fields for this operation.
- Compare the complete example with the representation used by your own input before carrying the result into another step.
How to use the tool and how it works
- Enter targetWidth, itemWidth, itemCount. Use the exact text syntax, units and index conventions explained below.
- Run the tool. If input validation fails, correct the supplied fields before interpreting any result.
- Read result.signedGap, result.nonnegativeGapPossible. Interpret false, null and empty lists using the distinctions below; they can be valid outputs.
Require nonnegative targetWidth/itemWidth and integer itemCount at least two. signedGap is (targetWidth-itemCount*itemWidth)/(itemCount-1); flag whether it is nonnegative.1
| Input field | Meaning and representation | Accepted input |
|---|---|---|
| targetWidth | target width. | Finite number; zero or greater |
| itemWidth | item width. | Finite number; zero or greater |
| itemCount | item count. | Integer from 2 to 1e9 inclusive |
| Output field | Interpretation |
|---|---|
| result | Object containing the named outputs below. |
| result.signedGap | The signed gap value under the stated formula or text convention. |
| result.nonnegativeGapPossible | Flag for nonnegative gap possible under the exact condition described above. |
{
"input": {
"targetWidth": 100,
"itemWidth": 30,
"itemCount": 3
},
"output": {
"result": {
"signedGap": 5,
"nonnegativeGapPossible": true
}
}
} Limitations and assumptions
- A negative gap exposes insufficient width rather than being clipped. No outer margins, wrapping or CSS distribution rule is chosen.
- Rectangle arrays use [x,y,width,height] with nonnegative extents. All dimensions must use the same coordinate frame and unit; values are supplied rather than measured from a page.
- Every declared top-level field is required and unexpected fields are rejected. Numeric inputs must be finite; ordinary text fields are bounded to 8,192 UTF-16 code units, with tighter operation-specific limits where stated.
- String lists have at most 128 entries of at most 128 code units; matrices have at most 128 rows and columns. Larger numeric lists and parsed JSON have separate bounded budgets. Nonfinite results and excessively large serialized outputs are rejected.
- Indexes are zero-based and spans have an exclusive end unless explicitly stated otherwise. A valid false, null or empty-list result is distinct from malformed input.
Alternative or Complementary methods
Measure the actual layout when browser behavior matters. The formulas use supplied coordinates and explicit simplifications; they do not account for every box, writing mode, clipping ancestor or simultaneous layout change.
References
Similar or alternative tools
- Layout Adjacent Gap Measure
Measure signed physical adjacency gap from the first trailing edge to the second leading edge; negative means overlap along that axis.
- Layout Inset Content Rectangle
Compute axis-aligned inset content geometry, retaining an overconstrained flag when opposing insets exceed available size.