Exercise: Convert a form to a CSS grid layout
A possible solution is at the end of this page.
Open Exercise-ConvertToCssLayout.bbj from 05_CssLayouts.zip for the exercise source code.
This exercise for the CSS Layouts chapter consists of a window that has a contact form made up of labels and edit boxes. The window already uses flow layout, so if you run the program in this state, the contact form flows from left to right.
Goals:
-
Add code to the
json!JsonObject that is applied to the window to change the CSSdisplaytogrid, so the window adopts a CSS Grid layout. -
Augment the
json!variable to set thegrid-template-columnsCSS property of the window to a value that forces two columns, such asauto 1fr. -
Augment the
json!variable to add padding around the window and a gap between the rows and columns of the grid. -
Augment the
json!variable to vertically center the labels and edit boxes by setting thealign-itemsCSS property tocenter. -
Add a
setStyle()method call to the Submit button that sets the CSSgrid-columnproperty to a value that makes it span both columns of the grid. Hint: the value is the starting line (not column), followed by a/, followed by the ending line (not column). If it were given in columns, you could set the value to1 / 2. Since you have to supply grid lines, set the value to1 / 3or use the span syntax1 / span 2.
Possible solution
The starter file is Exercise-ConvertToCssLayout.bbj. The solution is in Exercise-ConvertToCssLayoutComplete-Grid.bbj, and you find all files in 05_CssLayouts.zip.