-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.json
More file actions
1703 lines (1703 loc) · 71.5 KB
/
content.json
File metadata and controls
1703 lines (1703 loc) · 71.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"sections": {
"overview": {
"title": "Overview",
"type": "regular",
"pages": {
"overview": {
"title": "Construct 3 Flexbox Layout Engine",
"addonCards": [
{
"title": "UI Element",
"description": "The core plugin that provides flexbox layout capabilities for individual UI objects with CSS-like styling",
"icon": "Flexbox.png",
"storeUrl": "https://www.construct.net/en/make-games/addons/1450/ui-element",
"sourceUrl": "https://github.com/skymen/flexbox",
"price": "Free"
},
{
"title": "UI Controller",
"description": "The management system that orchestrates layouts across multiple UI elements and handles style inheritance",
"icon": "FlexboxController.png",
"storeUrl": "https://www.construct.net/en/make-games/addons/1451/ui-controller",
"sourceUrl": "https://github.com/skymen/flexboxController",
"price": "Free"
}
],
"content": [
"A powerful layout engine for Construct 3 that brings CSS Flexbox-like functionality to game object positioning and sizing. Style your UI elements using familiar CSS syntax.",
{
"type": "heading",
"level": 2,
"text": "Two Essential Free Addons"
},
"This layout system consists of two complementary addons available for free on the Construct 3 addon exchange:",
{
"type": "note",
"text": "<strong>Important:</strong> Both addons are required to use the complete flexbox layout system. The UI Element handles individual object styling, while the UI Controller manages the overall layout coordination."
},
{
"type": "heading",
"level": 2,
"text": "Features"
},
{
"type": "list",
"items": [
"CSS-like property syntax with kebab-case and camelCase support",
"Complete flexbox implementation (flex-grow, flex-shrink, flex-basis)",
"Multiple layout modes: vertical, horizontal, and grid",
"Box model support: margin, padding, border",
"Positioning: relative, absolute, and anchor-based",
"Percentage-based sizing and constraints",
"Style inheritance and cascading with !important support",
"Real-time layout updates and responsive design",
"Integration with Construct 3's native object system"
]
},
{
"type": "heading",
"level": 2,
"text": "How it works"
},
"The layout engine processes objects in the following order:",
{
"type": "list",
"ordered": true,
"items": [
"Parse CSS-like styles from registered classes and inline styles",
"Apply sizing properties and constraints",
"Recursively process child objects to establish base sizes",
"Apply layout algorithms (flexbox, grid) to in-flow children",
"Handle fit-content sizing and reflow as needed",
"Position out-of-flow elements (absolute, anchor)"
]
},
{
"type": "note",
"text": "<strong>Note:</strong> This engine is designed specifically for Construct 3 and operates on WorldInstance objects with getBoundingBox() and positioning APIs."
}
]
},
"basic-concepts": {
"title": "Basic Concepts",
"content": [
{
"type": "heading",
"level": 2,
"text": "Layout Flow"
},
"Elements participate in different types of layout flow:",
{
"type": "list",
"items": [
"<strong>Normal Flow:</strong> Elements are laid out according to their display property (vertical, horizontal, grid)",
"<strong>Out-of-Flow:</strong> Absolutely or anchor-positioned elements that don't affect other elements"
]
},
{
"type": "heading",
"level": 2,
"text": "Container vs Items"
},
"In flexbox layouts:",
{
"type": "list",
"items": [
"<strong>Container:</strong> The parent element with <code class=\"inline-code\">display: horizontal</code> or <code class=\"inline-code\">display: vertical</code>",
"<strong>Items:</strong> Direct children of the container that are positioned by the layout algorithm"
]
},
{
"type": "heading",
"level": 2,
"text": "Main and Cross Axis"
},
{
"type": "list",
"items": [
"<strong>Horizontal layout:</strong> Main axis is horizontal (left to right), cross axis is vertical",
"<strong>Vertical layout:</strong> Main axis is vertical (top to bottom), cross axis is horizontal"
]
}
]
}
}
},
"css": {
"title": "CSS Syntax",
"type": "regular",
"pages": {
"syntax-basics": {
"title": "Basic Syntax",
"content": [
{
"type": "heading",
"level": 2,
"text": "Property Format"
},
"Styles are written using CSS-like syntax. Properties are separated by line breaks or semicolons:",
{
"type": "code",
"text": "display: horizontal;\ngap: 10;\nalign-items: center;\njustify-content: space-between;"
},
{
"type": "heading",
"level": 2,
"text": "Property Names"
},
"Properties can be written in either kebab-case or camelCase:",
{
"type": "code",
"text": "/* Both formats are equivalent */\nalign-items: center;\nalignItems: center;\n\nflex-grow: 1;\nflexGrow: 1;"
},
{
"type": "heading",
"level": 2,
"text": "Value Types"
},
{
"type": "list",
"items": [
"<strong>Numbers:</strong> <code class=\"inline-code\">10</code>, <code class=\"inline-code\">3.5</code>, <code class=\"inline-code\">0</code>",
"<strong>Strings:</strong> <code class=\"inline-code\">center</code>, <code class=\"inline-code\">auto</code>, <code class=\"inline-code\">100px</code>",
"<strong>Percentages:</strong> <code class=\"inline-code\">50%</code>, <code class=\"inline-code\">100%</code>",
"<strong>Keywords:</strong> <code class=\"inline-code\">auto</code>, <code class=\"inline-code\">none</code>, <code class=\"inline-code\">initial</code>"
]
}
]
},
"property-formats": {
"title": "Property Formats",
"content": [
{
"type": "heading",
"level": 2,
"text": "Important Declarations"
},
"Use <code class=\"inline-code\">!important</code> to override other styles:",
{
"type": "code",
"text": "width: 200 !important;\nheight: 100 !important;"
},
{
"type": "heading",
"level": 2,
"text": "Shorthand Properties"
},
"Some properties support shorthand notation:",
{
"type": "code",
"text": "/* Margin shorthand: top right bottom left */\nmargin: 10 20 10 20;\n\n/* Individual margin properties */\nmargin-top: 10;\nmargin-right: 20;\nmargin-bottom: 10;\nmargin-left: 20;"
},
{
"type": "warning",
"text": "<strong>Syntax Notes:</strong><br><ul><li>Semicolons are optional; line breaks separate properties</li><li>Zero values with units (0px, 0%) are converted to 0</li><li>Pure numbers become numeric types, values with units remain strings</li><li>Whitespace around colons and values is ignored</li></ul>"
}
]
},
"flex-shorthand": {
"title": "Flex Shorthand",
"content": [
"The <code class=\"inline-code\">flex</code> property is shorthand for flex-grow, flex-shrink, and flex-basis:",
{
"type": "heading",
"level": 2,
"text": "Single Value Syntax"
},
{
"type": "code",
"text": "/* Number: sets flex-grow, defaults others */\nflex: 1; /* flex-grow: 1, flex-shrink: 1, flex-basis: 0 */\n\n/* Keywords */\nflex: auto; /* flex-grow: 1, flex-shrink: 1, flex-basis: auto */\nflex: none; /* flex-grow: 0, flex-shrink: 0, flex-basis: auto */\nflex: initial; /* flex-grow: 0, flex-shrink: 1, flex-basis: auto */"
},
{
"type": "heading",
"level": 2,
"text": "Two Value Syntax"
},
{
"type": "code",
"text": "/* flex-grow and flex-shrink */\nflex: 1 2; /* flex-grow: 1, flex-shrink: 2, flex-basis: 0 */\n\n/* flex-grow and flex-basis */\nflex: 1 100px; /* flex-grow: 1, flex-shrink: 1, flex-basis: 100px */"
},
{
"type": "heading",
"level": 2,
"text": "Three Value Syntax"
},
{
"type": "code",
"text": "/* flex-grow, flex-shrink, and flex-basis */\nflex: 1 2 100px; /* flex-grow: 1, flex-shrink: 2, flex-basis: 100px */"
}
]
}
}
},
"guides": {
"title": "Guides",
"type": "regular",
"pages": {
"layout-basics": {
"title": "Layout Basics Guide",
"content": [
{
"type": "step",
"number": 1,
"title": "Choose a Display Mode",
"content": [
"Start by setting the <code class=\"inline-code\">display</code> property on your container:",
{
"type": "code",
"text": "/* For stacking elements vertically */\ndisplay: vertical;\n\n/* For arranging elements horizontally */\ndisplay: horizontal;\n\n/* For grid-based layouts */\ndisplay: grid;"
}
]
},
{
"type": "step",
"number": 2,
"title": "Add Spacing",
"content": [
"Control spacing between child elements:",
{
"type": "code",
"text": "/* Add 10 pixels between each child */\ngap: 10;"
}
]
},
{
"type": "step",
"number": 3,
"title": "Control Alignment",
"content": [
"Align children within the container:",
{
"type": "code",
"text": "/* Align children on the cross-axis */\nalign-items: center; /* start, center, end */\n\n/* Distribute children on the main axis */\njustify-content: space-between; /* start, center, end, space-between, space-around */"
}
]
}
]
},
"flexbox-guide": {
"title": "Using Flexbox Guide",
"content": [
{
"type": "step",
"number": 1,
"title": "Understanding Flex Items",
"content": [
"By default, children in a flex container maintain their natural size. Use flex properties to make them flexible:",
{
"type": "code",
"text": "/* Make an item grow to fill available space */\nflex-grow: 1;\n\n/* Make an item shrink when space is limited */\nflex-shrink: 2;\n\n/* Set the initial size before growing/shrinking */\nflex-basis: 200;"
}
]
},
{
"type": "step",
"number": 2,
"title": "Common Flex Patterns",
"content": [
"Here are common flex patterns:",
{
"type": "code",
"text": "/* Equal width columns */\nflex: 1;\n\n/* Fixed sidebar, flexible content */\n/* Sidebar: */ flex-shrink: 0; width: 200;\n/* Content: */ flex-grow: 1;\n\n/* Flexible with minimum size */\nflex: 1; min-width: 150;"
}
]
},
{
"type": "step",
"number": 3,
"title": "Individual Item Alignment",
"content": [
"Override container alignment for specific items:",
{
"type": "code",
"text": "/* Override align-items for this item only */\nalign-self: end;"
}
]
}
]
},
"positioning-guide": {
"title": "Positioning Elements Guide",
"content": [
{
"type": "step",
"number": 1,
"title": "Relative Positioning",
"content": [
"Default positioning mode. Elements participate in normal layout flow:",
{
"type": "code",
"text": "position: relative; /* Default, can be omitted */"
}
]
},
{
"type": "step",
"number": 2,
"title": "Absolute Positioning",
"content": [
"Remove element from normal flow and position relative to parent:",
{
"type": "code",
"text": "position: absolute;\ntop: 20; /* 20 pixels from parent's top */\nright: 20; /* 20 pixels from parent's right */"
}
]
},
{
"type": "step",
"number": 3,
"title": "Anchor Positioning",
"content": [
"Position relative to another element:",
{
"type": "code",
"text": "position: anchor;\nanchor-target: button1; /* Target element tag */\nanchor-point: bottom-center; /* Point on target */\nself-anchor: top-center; /* Point on this element */\nanchor-offset-y: 10; /* Additional offset */"
}
]
}
]
},
"anchor-positioning-guide": {
"title": "Anchor Positioning Guide",
"content": [
"Anchor positioning is one of the most powerful features of the Construct 3 Flexbox Layout Engine. It allows you to position elements relative to other elements anywhere in your game world, making it perfect for tooltips, health bars, UI overlays, and contextual menus.",
{
"type": "warning",
"text": "<strong>Key Concept:</strong> Anchor positioning removes the element from normal layout flow, so it won't affect the positioning of other elements. Think of it as a floating layer that can follow other objects."
},
{
"type": "step",
"number": 1,
"title": "Basic Anchor Setup",
"content": [
"To enable anchor positioning, you need three essential properties:",
{
"type": "code",
"text": "/* Enable anchor positioning */\nposition: anchor;\n\n/* Choose what to anchor to */\nanchor-target: button1;\n\n/* Choose where to attach */\nanchor-point: bottom;"
},
"This basic setup will position your element at the bottom edge of 'button1'. The element's center will align with the target's bottom edge."
]
},
{
"type": "step",
"number": 2,
"title": "Understanding Anchor Points",
"content": [
"Both the target element and your anchored element have 9 possible anchor points:",
{
"type": "code",
"text": "/* Corner points */\ntop-left top-right\nleft center right\nbottom-left bottom bottom-right\n\n/* Visual layout */\n┌─────────┬─────────┐\n│top-left │ top │top-right\n├─────────┼─────────┤\n│ left │ center │ right\n├─────────┼─────────┤\n│bottom- │ bottom │bottom-\n│left │ │right\n└─────────┴─────────┘"
},
{
"type": "note",
"text": "<strong>Tip:</strong> Use corner and edge points for precise alignment. The center point is perfect for overlays and centered tooltips."
}
]
},
{
"type": "step",
"number": 3,
"title": "Controlling Your Element's Attachment Point",
"content": [
"By default, your element attaches using its center point. Use <code class=\"inline-code\">self-anchor</code> to change this:",
{
"type": "code",
"text": "/* Tooltip above a button */\nposition: anchor;\nanchor-target: helpButton;\nanchor-point: top; /* Target's top edge */\nself-anchor: bottom; /* This element's bottom edge */\n\n/* Result: Tooltip appears above button with no overlap */"
},
"Common self-anchor patterns:",
{
"type": "code",
"text": "/* Dropdown menu */\nanchor-point: bottom;\nself-anchor: top;\n\n/* Side panel */\nanchor-point: right;\nself-anchor: left;\n\n/* Centered overlay */\nanchor-point: center;\nself-anchor: center;"
}
]
},
{
"type": "step",
"number": 4,
"title": "Fine-tuning with Offsets",
"content": [
"Use anchor offsets to add spacing or make micro-adjustments:",
{
"type": "code",
"text": "/* Tooltip with spacing */\nposition: anchor;\nanchor-target: button;\nanchor-point: top;\nself-anchor: bottom;\nanchor-offset-y: -10; /* 10px gap above button */\n\n/* Notification badge */\nposition: anchor;\nanchor-target: avatar;\nanchor-point: top-right;\nself-anchor: center;\nanchor-offset-x: 8; /* Slight offset to the right */\nanchor-offset-y: -8; /* Slight offset upward */"
},
{
"type": "note",
"text": "<strong>Coordinate System:</strong> Positive X moves right, negative X moves left. Positive Y moves down, negative Y moves up."
}
]
},
{
"type": "step",
"number": 5,
"title": "Choosing Anchor Targets",
"content": [
"You can anchor to different types of targets:",
{
"type": "code",
"text": "/* Anchor to parent element */\nanchor-target: parent;\n\n/* Anchor to any game object by tag */\nanchor-target: player;\nanchor-target: healthBar;\nanchor-target: inventoryButton;\n\n/* Anchor to UI elements */\nanchor-target: menuButton;\nanchor-target: scoreDisplay;"
},
{
"type": "warning",
"text": "<strong>Important:</strong> Make sure your target objects have the correct tags in Construct 3. The anchor system searches for objects with matching tag names."
}
]
},
{
"type": "example",
"title": "Practical Example: Game UI Tooltip",
"content": [
"Let's create a tooltip that appears above a skill button when the player hovers over it:",
{
"type": "code",
"text": "/* Tooltip container */\nposition: anchor;\nanchor-target: skillButton; /* Target the skill button */\nanchor-point: top; /* Attach to button's top edge */\nself-anchor: bottom; /* Using tooltip's bottom edge */\nanchor-offset-y: -15; /* 15px spacing above button */\nwidth: 200;\npadding: 10;\nbackground-color: #2c3e50;\ncolor: white;\nborder-radius: 4px;\n\n/* Optional: Add arrow/tail effect with another anchored element */\n/* Arrow */\nposition: anchor;\nanchor-target: skillButton;\nanchor-point: top;\nself-anchor: top;\nanchor-offset-y: -5;\nwidth: 10;\nheight: 10;\nbackground-color: #2c3e50;\n/* Note: You'd style the arrow shape in Construct 3 */"
}
]
},
{
"type": "example",
"title": "Practical Example: Health Bar Above Character",
"content": [
"Create a health bar that follows a character:",
{
"type": "code",
"text": "/* Health bar background */\nposition: anchor;\nanchor-target: player; /* Follows the player object */\nanchor-point: top; /* Above the player */\nself-anchor: bottom;\nanchor-offset-y: -20; /* 20px above player */\nwidth: 60;\nheight: 8;\nbackground-color: #e74c3c;\n\n/* Health bar fill (child of background) */\nposition: relative; /* Normal flow within health bar */\nheight: 100%;\nwidth: 75%; /* 75% health */\nbackground-color: #27ae60;"
}
]
},
{
"type": "example",
"title": "Practical Example: Contextual Menu",
"content": [
"A menu that appears next to an inventory item:",
{
"type": "code",
"text": "/* Context menu container */\nposition: anchor;\nanchor-target: inventorySlot;\nanchor-point: right; /* To the right of the slot */\nself-anchor: left; /* Menu's left edge */\nanchor-offset-x: 10; /* Small gap */\ndisplay: vertical;\nwidth: 120;\npadding: 5;\nbackground-color: #34495e;\nborder-radius: 4px;\n\n/* Menu items (children of container) */\nposition: relative;\nheight: 30;\npadding: 5 10;\ncolor: white;\nborder-radius: 2px;\n\n/* Menu items can have hover effects, spacing, etc. */"
}
]
},
{
"type": "step",
"number": 6,
"title": "Common Patterns and Best Practices",
"content": [
{
"type": "heading",
"level": 3,
"text": "Tooltip Pattern"
},
{
"type": "code",
"text": "/* Above target */\nanchor-point: top; self-anchor: bottom; anchor-offset-y: -gap;\n\n/* Below target */\nanchor-point: bottom; self-anchor: top; anchor-offset-y: gap;\n\n/* Left of target */\nanchor-point: left; self-anchor: right; anchor-offset-x: -gap;\n\n/* Right of target */\nanchor-point: right; self-anchor: left; anchor-offset-x: gap;"
},
{
"type": "heading",
"level": 3,
"text": "Overlay Pattern"
},
{
"type": "code",
"text": "/* Centered overlay */\nanchor-point: center;\nself-anchor: center;\n\n/* Corner badge */\nanchor-point: top-right;\nself-anchor: center;\nanchor-offset-x: 5;\nanchor-offset-y: -5;"
},
{
"type": "heading",
"level": 3,
"text": "Following Elements"
},
{
"type": "code",
"text": "/* Health/status bars */\nanchor-point: top;\nself-anchor: bottom;\nanchor-offset-y: -distance;\n\n/* Name tags */\nanchor-point: bottom;\nself-anchor: top;\nanchor-offset-y: distance;"
}
]
},
{
"type": "step",
"number": 7,
"title": "Troubleshooting Common Issues",
"content": [
{
"type": "heading",
"level": 3,
"text": "Element Not Appearing"
},
{
"type": "list",
"items": [
"Check that the anchor-target object exists and has the correct tag",
"Verify that position is set to 'anchor'",
"Make sure the anchored element has a size (width/height)"
]
},
{
"type": "heading",
"level": 3,
"text": "Wrong Position"
},
{
"type": "list",
"items": [
"Check anchor-point and self-anchor combination",
"Verify anchor-offset-x and anchor-offset-y signs (positive/negative)",
"Remember that the target might be moving or changing size"
]
},
{
"type": "heading",
"level": 3,
"text": "Performance Considerations"
},
{
"type": "list",
"items": [
"Anchor positioning updates automatically when targets move",
"Use sparingly for many dynamic elements",
"Consider disabling/enabling anchored elements when not needed"
]
}
]
},
{
"type": "note",
"text": "<strong>Remember:</strong> Anchor positioning is perfect for UI elements that need to follow game objects or appear contextually. It's ideal for tooltips, health bars, menus, and overlays, but use it thoughtfully for performance in complex scenes."
}
]
},
"responsive-guide": {
"title": "Responsive Layouts Guide",
"content": [
{
"type": "step",
"number": 1,
"title": "Percentage-based Sizing",
"content": [
"Make elements resize based on their parent:",
{
"type": "code",
"text": "/* 50% of parent width */\npercent-width: 50;\n\n/* 100% of parent height */\npercent-height: 100;\n\n/* Or using string percentages */\nwidth: 50%;\nheight: 100%;"
}
]
},
{
"type": "step",
"number": 2,
"title": "Constraints",
"content": [
"Set minimum and maximum sizes to prevent elements from becoming too small or large:",
{
"type": "code",
"text": "percent-width: 50;\nmin-width: 200; /* Never smaller than 200 pixels */\nmax-width: 800; /* Never larger than 800 pixels */"
}
]
},
{
"type": "step",
"number": 3,
"title": "Flexible Containers",
"content": [
"Use fit-content to make containers size to their children:",
{
"type": "code",
"text": "fit-content: true; /* Container sizes to fit its children */"
}
]
}
]
},
"common-patterns": {
"title": "Common Layout Patterns",
"content": [
{
"type": "example",
"title": "Navigation Bar",
"content": [
{
"type": "code",
"text": "/* Container */\ndisplay: horizontal;\ngap: 20;\nalign-items: center;\njustify-content: space-between;\npadding: 10;"
}
]
},
{
"type": "example",
"title": "Sidebar Layout",
"content": [
{
"type": "code",
"text": "/* Main Container */\ndisplay: horizontal;\ngap: 20;\n\n/* Sidebar */\nwidth: 250;\nflex-shrink: 0;\n\n/* Content Area */\nflex-grow: 1;"
}
]
},
{
"type": "example",
"title": "Card Layout",
"content": [
{
"type": "code",
"text": "/* Card Container */\ndisplay: vertical;\nheight: 400;\n\n/* Header */\nheight: 60;\nflex-shrink: 0;\n\n/* Content */\nflex-grow: 1;\npadding: 20;\n\n/* Footer */\nheight: 40;\nflex-shrink: 0;"
}
]
},
{
"type": "example",
"title": "Centered Modal",
"content": [
{
"type": "code",
"text": "position: anchor;\nanchor-target: parent;\nanchor-point: center;\nself-anchor: center;\nwidth: 400;\nheight: 300;"
}
]
}
]
}
}
},
"properties": {
"title": "Properties",
"type": "property",
"pages": {
"prop-display": {
"name": "display",
"description": "Sets the layout algorithm for child elements",
"values": "vertical | horizontal | grid",
"default": "vertical",
"content": [
{
"type": "heading",
"level": 2,
"text": "Description"
},
"The <code class=\"inline-code\">display</code> property determines how child elements are laid out within their container. This is the primary property that controls the layout algorithm.",
{
"type": "heading",
"level": 2,
"text": "Values"
},
{
"type": "list",
"items": [
"<strong>vertical:</strong> Children are stacked vertically (top to bottom)",
"<strong>horizontal:</strong> Children are arranged horizontally (left to right)",
"<strong>grid:</strong> Children are arranged in a grid pattern"
]
},
{
"type": "heading",
"level": 2,
"text": "Examples"
},
{
"type": "code",
"text": "/* Stack buttons vertically */\ndisplay: vertical;\ngap: 10;\n\n/* Arrange menu items horizontally */\ndisplay: horizontal;\ngap: 20;\n\n/* Create a grid of thumbnails */\ndisplay: grid;\ncolumns: 3;\ngap: 15;"
},
{
"type": "heading",
"level": 2,
"text": "Notes"
},
{
"type": "list",
"items": [
"Only affects direct children of the element",
"Out-of-flow positioned children (absolute, anchor) are not affected",
"Default behavior is vertical stacking if not specified"
]
}
]
},
"prop-position": {
"name": "position",
"description": "Sets how the element is positioned",
"values": "relative | absolute | anchor",
"default": "relative",
"content": [
{
"type": "heading",
"level": 2,
"text": "Description"
},
"Controls how an element is positioned within its parent and whether it participates in normal layout flow.",
{
"type": "heading",
"level": 2,
"text": "Values"
},
{
"type": "list",
"items": [
"<strong>relative:</strong> Element participates in normal layout flow",
"<strong>absolute:</strong> Element is positioned relative to its parent's content area",
"<strong>anchor:</strong> Element is positioned relative to another element"
]
},
{
"type": "heading",
"level": 2,
"text": "Examples"
},
{
"type": "code",
"text": "/* Normal layout flow */\nposition: relative;\n\n/* Position in corner of parent */\nposition: absolute;\ntop: 10;\nright: 10;\n\n/* Position relative to another element */\nposition: anchor;\nanchor-target: button1;"
}
]
},
"prop-gap": {
"name": "gap",
"description": "Sets space between child elements",
"values": "number",
"default": "0",
"content": [
{
"type": "heading",
"level": 2,
"text": "Description"
},
"Adds consistent spacing between child elements in flex and grid layouts. The gap is applied between elements, not around them.",
{
"type": "heading",
"level": 2,
"text": "Examples"
},
{
"type": "code",
"text": "/* 10 pixel gap between children */\ngap: 10;\n\n/* No gap (default) */\ngap: 0;"
},
{
"type": "heading",
"level": 2,
"text": "Notes"
},
{
"type": "list",
"items": [
"Gap is added between elements, not before the first or after the last",
"Works with all display modes (vertical, horizontal, grid)",
"Does not affect absolutely or anchor-positioned children"
]
}
]
},
"prop-flex": {
"name": "flex",
"description": "Shorthand for flex-grow, flex-shrink, and flex-basis",
"values": "number | auto | none | initial | \"grow shrink basis\"",
"default": "0 1 auto",
"content": [
{
"type": "heading",
"level": 2,
"text": "Description"
},
"A shorthand property that sets flex-grow, flex-shrink, and flex-basis in a single declaration. This is the most common way to make elements flexible.",
{
"type": "heading",
"level": 2,
"text": "Syntax Variations"
},
{
"type": "code",
"text": "/* Single number: flex-grow */\nflex: 1; /* flex-grow: 1, flex-shrink: 1, flex-basis: 0 */\n\n/* Keywords */\nflex: auto; /* 1 1 auto */\nflex: none; /* 0 0 auto */\nflex: initial; /* 0 1 auto */\n\n/* Two values */\nflex: 1 2; /* grow: 1, shrink: 2, basis: 0 */\nflex: 1 100px; /* grow: 1, shrink: 1, basis: 100px */\n\n/* Three values */\nflex: 1 2 100px; /* grow: 1, shrink: 2, basis: 100px */"
},
{
"type": "heading",
"level": 2,
"text": "Common Patterns"
},
{
"type": "code",
"text": "/* Equal width flexible items */\nflex: 1;\n\n/* Fixed size, won't grow or shrink */\nflex: none;\n\n/* Flexible but with minimum size */\nflex: 1;\nmin-width: 200;"
}
]
},
"prop-flex-grow": {
"name": "flex-grow",
"description": "How much the item should grow relative to other flex items",
"values": "number ≥ 0",
"default": "0",
"content": [
{
"type": "heading",
"level": 2,
"text": "Description"
},
"Defines how much an item should grow when there is extra space available in the flex container. The value is a ratio relative to other flex items.",
{
"type": "heading",
"level": 2,
"text": "Examples"
},
{
"type": "code",
"text": "/* Item won't grow (default) */\nflex-grow: 0;\n\n/* Item will grow to fill available space */\nflex-grow: 1;\n\n/* Item will grow twice as much as items with flex-grow: 1 */\nflex-grow: 2;"
},
{
"type": "heading",
"level": 2,
"text": "How it works"
},
"If multiple items have flex-grow values, the available space is distributed proportionally:",
{
"type": "list",
"items": [
"Item A: <code class=\"inline-code\">flex-grow: 1</code> gets 1/3 of extra space",
"Item B: <code class=\"inline-code\">flex-grow: 2</code> gets 2/3 of extra space"
]
}
]
},
"prop-flex-shrink": {
"name": "flex-shrink",
"description": "How much the item should shrink relative to other flex items",
"values": "number ≥ 0",
"default": "1",
"content": [
{
"type": "heading",
"level": 2,
"text": "Description"
},
"Defines how much an item should shrink when there isn't enough space in the flex container. Higher values shrink more.",
{
"type": "heading",
"level": 2,
"text": "Examples"
},
{
"type": "code",
"text": "/* Item won't shrink */\nflex-shrink: 0;\n\n/* Item will shrink normally (default) */\nflex-shrink: 1;\n\n/* Item will shrink twice as much as normal */\nflex-shrink: 2;"
},
{
"type": "heading",
"level": 2,
"text": "Common Use Cases"
},
{
"type": "code",
"text": "/* Fixed sidebar that won't shrink */\nwidth: 250;\nflex-shrink: 0;\n\n/* Flexible content that can shrink */\nflex-grow: 1;\nflex-shrink: 1;"
}
]
},
"prop-flex-basis": {
"name": "flex-basis",
"description": "Initial main size before free space is distributed",
"values": "number | percentage | auto",
"default": "auto",
"content": [
{
"type": "heading",
"level": 2,
"text": "Description"
},
"Sets the initial size of the item before any growing or shrinking occurs. This is the starting point for flex calculations.",
{
"type": "heading",
"level": 2,
"text": "Examples"
},
{
"type": "code",
"text": "/* Use the item's natural size */\nflex-basis: auto;\n\n/* Start with 200 pixels */\nflex-basis: 200;\n\n/* Start with 50% of container */\nflex-basis: 50%;"
},
{
"type": "heading",
"level": 2,
"text": "Interaction with width/height"
},
"In horizontal layouts, flex-basis overrides width. In vertical layouts, it overrides height.",
{
"type": "code",
"text": "/* In horizontal layout */\nwidth: 100; /* This is ignored */\nflex-basis: 200; /* Item starts at 200px wide */"
}
]
},
"prop-align-items": {
"name": "align-items",
"description": "Aligns children along the cross-axis",
"values": "start | center | end",
"default": "start",
"content": [
{
"type": "heading",
"level": 2,
"text": "Description"
},
"Controls how children are aligned perpendicular to the main layout direction. Also available as <code class=\"inline-code\">alignment</code> for shorter syntax.",
{
"type": "heading",
"level": 2,
"text": "Cross-axis direction"
},
{
"type": "list",
"items": [
"<strong>Horizontal layout:</strong> Cross-axis is vertical (top to bottom)",
"<strong>Vertical layout:</strong> Cross-axis is horizontal (left to right)"
]
},
{
"type": "heading",
"level": 2,
"text": "Examples"
},
{
"type": "code",
"text": "/* Align to start of cross-axis (default) */\nalign-items: start;\n\n/* Center on cross-axis */\nalign-items: center;\n\n/* Align to end of cross-axis */\nalign-items: end;\n\n/* Shorter syntax */\nalignment: center;"
},
{
"type": "heading",
"level": 2,
"text": "Visual Examples"
},
{
"type": "code",
"text": "/* Horizontal layout with vertical centering */\ndisplay: horizontal;\nalign-items: center; /* Centers vertically */\n\n/* Vertical layout with horizontal centering */\ndisplay: vertical;\nalign-items: center; /* Centers horizontally */"
}
]
},
"prop-justify-content": {
"name": "justify-content",
"description": "Aligns children along the main axis",
"values": "start | center | end | space-between | space-around",
"default": "start",
"content": [
{
"type": "heading",
"level": 2,
"text": "Description"
},
"Controls how children are distributed along the main layout direction when there is extra space available.",
{
"type": "heading",
"level": 2,
"text": "Values"
},
{
"type": "list",
"items": [
"<strong>start:</strong> Items packed at start",
"<strong>center:</strong> Items centered",
"<strong>end:</strong> Items packed at end",
"<strong>space-between:</strong> Equal space between items",
"<strong>space-around:</strong> Equal space around items"
]
},
{
"type": "heading",
"level": 2,
"text": "Examples"
},
{
"type": "code",
"text": "/* Center navigation items */\ndisplay: horizontal;\njustify-content: center;\n\n/* Spread items across full width */\ndisplay: horizontal;\njustify-content: space-between;\n\n/* Equal spacing around each item */\ndisplay: horizontal;\njustify-content: space-around;"
}
]
},
"prop-align-self": {
"name": "align-self",
"description": "Overrides align-items for individual child",
"values": "start | center | end",
"default": "Inherits from parent's align-items",
"content": [
{