Skip to content

Implement CSS box model spacing and inline-block layout - #73

Draft
aymanbagabas with Copilot wants to merge 6 commits into
docfrom
copilot/implement-html-css-box-model
Draft

Implement CSS box model spacing and inline-block layout#73
aymanbagabas with Copilot wants to merge 6 commits into
docfrom
copilot/implement-html-css-box-model

Conversation

Copilot AI commented Jan 26, 2026

Copy link
Copy Markdown

Continues box model implementation on doc branch per CSS 2.1 spec. Adds margin, padding, border properties with full CSS shorthand parsing, updates layout engine to account for spacing, and implements inline-block display type.

Box Model Properties

Added 12 spacing properties to ComputedStyle:

MarginTop, MarginRight, MarginBottom, MarginLeft       int
PaddingTop, PaddingRight, PaddingBottom, PaddingLeft   int  
BorderTop, BorderRight, BorderBottom, BorderLeft       int

All values in terminal cells. Units (px, em, rem, %) stripped during parse.

CSS Parsing

Supports full CSS shorthand syntax:

<div style="margin: 10">             <!-- all sides -->
<div style="padding: 5 10">          <!-- vertical horizontal -->
<div style="margin: 1 2 3">          <!-- top horizontal bottom -->
<div style="border: 1 2 3 4">        <!-- top right bottom left -->

Individual properties work: margin-top: 5, padding-left: 10, etc.

Layout Calculations

Added helpers in renderer.go:

  • calculateContentWidth() - available width minus spacing
  • applyBoxModelSpacing() - computes ContentRect, PaddingRect, BorderRect, MarginRect
  • Updated layoutBlockBox() to position children within parent's content area and apply vertical margins between blocks

Example box calculation:

Total = margin + border + padding + content + padding + border + margin
Width = 2 + 1 + 5 + 74 + 5 + 1 + 2 = 90 cells

Inline-Block Display

Added DisplayInlineBlock type. Boxes flow inline but establish block formatting context internally. Treated as inline-level in box tree (IsInline() returns true).

Testing

  • box_model_spacing_test.go - unit tests for parsing and calculations
  • box_model_integration_test.go - integration tests with HTML examples
  • BOX_MODEL.md - implementation documentation

Not Implemented

  • Margin collapsing (adjacent vertical margins)
  • Border styles/colors (width only)
  • box-sizing property
  • Percentage-based spacing

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • go.googlesource.com
    • Triggering command: /update-job-proxy /update-job-proxy /home/REDACTED/work/_temp/runtime-logs/mkcert/rootCA.pem --updater-env NODE_EXTRA_CA_CERTS=/usr/local/share/ca-certificates/dbot-ca.crt 6016�� odel ache/go/1.24.12/x64/src/runtime/cgo ux_amd64/link 6016834/b142/ /tmp/go-build372rev-parse (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy DROP tnet/tools/bash test -e rking.pem findmnt test 79701f2e red_ID_Root_G3.cconfig 79701f2e c951ccea6f2dc8fa035a7c38e2633047--add -e 1.pem /opt/hostedtoolcache/go/1.24.12/x64/pkg/tool/lin-e /usr/bin/test y _-_G1.crt ntime.v2.task/mo-t test (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Look at the doc branch and continue implementing the html and css box model.

https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Display/Block_and_inline_layout


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 5 commits January 26, 2026 01:12
Co-authored-by: aymanbagabas <3187948+aymanbagabas@users.noreply.github.com>
… and inline-block display

Co-authored-by: aymanbagabas <3187948+aymanbagabas@users.noreply.github.com>
Co-authored-by: aymanbagabas <3187948+aymanbagabas@users.noreply.github.com>
Copilot AI changed the title [WIP] Continue implementing the HTML and CSS box model Implement CSS box model spacing and inline-block layout Jan 26, 2026
Copilot AI requested a review from aymanbagabas January 26, 2026 01:23
@aymanbagabas
aymanbagabas changed the base branch from main to doc January 26, 2026 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants