# Spacer

[🔰 CSS](/web/css.md) ⟩ [Layout](/web/css/layout.md) ⟩ [System](/web/css/layout/system.md) ⟩

{% tabs %}
{% tab title="👥 相關" %}

* [VStack](/web/css/layout/system/vstack.md)
  {% endtab %}

{% tab title="Second Tab" %}

{% endtab %}
{% endtabs %}

給 [VStack](/web/css/layout/system/vstack.md) 與 HStack 當「將 children 隔開用」的元素。

## axiom

{% hint style="info" %}

* **box-sizing: border-box** (長寬包含邊線)
* **width: 0** 或 **height: 0**
* **border: none** (不能有邊線)
* 具有 **margin-left: auto** 或 **margin-top: auto**
  {% endhint %}

## code example

{% tabs %}
{% tab title="spacer: prototype" %}
{% embed url="<https://codesandbox.io/embed/spacer-g94ik?fontsize=14&hidenavigation=1&theme=dark>" %}
\<spacer>
{% endembed %}
{% endtab %}

{% tab title="CSS" %}

```css
/* ⭐️ spacer */
.hstack > .spacer {
  margin-left: auto;
  width: 0;
  border: none;
}

.vstack > .spacer {
  margin-top: auto;
  height: 0;
  border: none;
}
```

{% endtab %}

{% tab title="HTML" %}

```markup
<div class="hstack">
  <div class="spacer"></div>
  <div></div>
  <div class="spacer"></div>
  <div></div>
  <div class="spacer"></div>
  <div></div>
</div>

<div class="vstack">
  <div class="spacer"></div>
  <div></div>
  <div class="spacer"></div>
  <div></div>
  <div class="spacer"></div>
  <div></div>
</div>
```

{% endtab %}

{% tab title="💾 程式" %}

* replit ⟩ [layout + spacer (v.2.0.1)](https://replit.com/@pegasusroe/layout-spacer-v201#index.html)
  {% endtab %}
  {% endtabs %}

{% tabs %}
{% tab title="spacer" %}
{% embed url="<https://codesandbox.io/s/layout-v-0-0-2-h8ler?file=/index.js>" %}
Spacer v.0.0.2
{% endembed %}
{% endtab %}

{% tab title="spacer.mjs" %}

```javascript
// Spacer
export default class Spacer extends HTMLElement {
}

// ⭐️ register new tag <i-Spacer>
customElements.get('i-spacer') || customElements.define('i-spacer', Spacer);
```

{% endtab %}

{% tab title="spacer.css" %}

```css
/* ⭐️ Spacer in HStack */

i-hstack > i-spacer {
  margin-left: auto !important;
  width: 0 !important;
  border: none !important;
}

/* ⭐️ Spacer in VStack */

i-vstack > i-spacer {
  margin-top: auto !important;
  height: 0 !important;
  border: none !important;
}
```

{% endtab %}

{% tab title="HTML" %}

```markup
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width">
	<title>layout + spacer</title>
	<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>

	<h1>VStack</h1>

	<fieldset>
		<legend> alignment: </legend>
		<select name="alignment" id="alignment">
            <option value="center">center (default)</option>
            <option value="stretch">stretch</option>
            <option value="flex-start">flex-start</option>
            <option value="flex-end">flex-end</option>
        </select>
    </fieldset>

    <i-vstack class="container">

        <i-vstack alignment="flex-start" spacing="0">
            <h2>VStack</h2>
            <i-spacer></i-spacer>
            <p>spacing: 0</p>
            <p>spacing: 0</p>
            <i-spacer></i-spacer>
            <p>alignment: flex-start</p>
            <p>alignment: flex-start</p>
        </i-vstack>

    </i-vstack>

    <!-- ⭐️ load layout system -->
    <script type="module" src="layout/index.mjs"></script>
    <script src="script.js"></script>

</body>
</html>
```

{% endtab %}

{% tab title="💾 程式" %}

* replit ⟩ [layout + spacer (v.2.0.1)](https://replit.com/@pegasusroe/layout-spacer-v201#index.html)
  {% endtab %}
  {% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/web/css/layout/system/spacer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
