Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTMLTableColElement.{align|valign} #33101

Merged
merged 7 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions files/en-us/web/api/htmltablecolelement/align/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: "HTMLTableColElement: align property"
short-title: align
slug: Web/API/HTMLTableColElement/align
page-type: web-api-instance-property
status:
- deprecated
browser-compat: api.HTMLTableColElement.align
---

{{APIRef("HTML DOM")}}{{deprecated_header}}

The **`align`** property of the {{domxref("HTMLTableColElement")}} interface is a string indicating how to horizontally align text in a column.
teoli2003 marked this conversation as resolved.
Show resolved Hide resolved

> **Note:** This property is deprecated, and CSS should be used to align text horizontally in a column. Use the CSS {{cssxref("text-align")}} property, which takes precedence, to horizontally align text in a column instead.
>
> As {{htmlelement("td")}} are not children of {{htmlelement("col")}}, you can't set it directly on a {{HTMLElement("col")}} element, you need to select the cells of the column using a `td:nth-child(n)` or similar (`n` is the column number).
estelle marked this conversation as resolved.
Show resolved Hide resolved
estelle marked this conversation as resolved.
Show resolved Hide resolved

## Value

The possible values are:

- `left`
- : Align the text to the left. Use `text-align: left` instead.
- `right`
- : Align the text to the right. Use `text-align: right` instead.
estelle marked this conversation as resolved.
Show resolved Hide resolved
- `center`
- : Center the text in the cell. Use `text-align: center` instead.
estelle marked this conversation as resolved.
Show resolved Hide resolved

## Examples

Use CSS `text-align`. As {{htmlelement("td")}} elements of a column are not children of {{htmlelement("col")}}, you can't set it directly on a {{HTMLElement("col")}}, you need to select the cells using a `td:nth-child(n)` or similar (`n` is the column number).
estelle marked this conversation as resolved.
Show resolved Hide resolved

An [example](/en-US/docs/Web/CSS/:nth-child#styling_a_table_column) is available on the {{cssxref(":nth-child()")}} page.

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{cssxref("text-align")}}
- {{cssxref(":nth-child()")}}
estelle marked this conversation as resolved.
Show resolved Hide resolved
- [Styling tables](/en-US/docs/Learn/CSS/Building_blocks/Styling_tables)
52 changes: 52 additions & 0 deletions files/en-us/web/api/htmltablecolelement/valign/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
title: "HTMLTableColElement: vAlign property"
short-title: vAlign
slug: Web/API/HTMLTableColElement/vAlign
page-type: web-api-instance-property
status:
- deprecated
browser-compat: api.HTMLTableColElement.vAlign
---

{{APIRef("HTML DOM")}}{{deprecated_header}}

The **`vAlign`** property of the {{domxref("HTMLTableColElement")}} interface is a string indicating how to vertically align text in a column.
estelle marked this conversation as resolved.
Show resolved Hide resolved

> **Note:** This property is deprecated, and CSS should be used to align text vertically in a column. Use the CSS {{cssxref("vertical-align")}} property, which takes precedence, to vertically align text in each column cell instead.
>
> As {{htmlelement("td")}} are not children of {{htmlelement("col")}}, you can't set it directly on a {{HTMLElement("col")}}element , you need to select the cells of the column using a `td:nth-child(n)` or similar (`n` is the column number).

## Value

The possible values are: `"top"`, `"middle"`, `"bottom"`, or `"baseline"`

- `top`
- : Align the text to the top of the column. Use `vertical-align: top` instead.
- `center`
- : Vertically center the text in the column. Synonym of `middle`. Use `vertical-align: middle` instead.
- `middle`
- : Vertically center the text in the column. Use `vertical-align: middle` instead.
- `bottom`
- : Align the text to the bottom of the column. Use `vertical-align: bottom` instead.
- `baseline`
- : Similar to `top`, but align the baseline of the text as close to the top so no part of the character is outside of the cell.

## Examples

Use CSS `vertical-align`. As {{htmlelement("td")}} elements of a column are not children of {{htmlelement("col")}}, you can't set it directly on a {{HTMLElement("col")}}, you need to select the cells using a `td:nth-child(n)` or similar (`n` is the column number).

An [example](/en-US/docs/Web/CSS/:nth-child#styling_a_table_column) is available on the {{cssxref(":nth-child()")}} page.

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{cssxref("vertical-align")}}
- {{cssxref(":nth-child()")}}
- [Styling tables](/en-US/docs/Learn/CSS/Building_blocks/Styling_tables)
52 changes: 52 additions & 0 deletions files/en-us/web/css/_colon_nth-child/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,58 @@ In the second table the _of syntax_ is used to target only the `tr`s that are **

{{EmbedLiveSample('Using_of_selector_to_fix_striped_tables', 550, 180)}}

### Styling a table column

To style a table column, you can't set the style on the {{HTMLElement("col")}} element as table cells are not children of it (as you can with the row element, {{HTMLElement("tr")}}). Pseudo-classes like `:nth-child()` are handy to select the column cells.

In this example, we set different styles for each of the column.

#### HTML

```html-nolint
<table>
estelle marked this conversation as resolved.
Show resolved Hide resolved
<thead>
<tr><th>Column 1</th><th>Column 2</th><th>Column3</th></tr>
estelle marked this conversation as resolved.
Show resolved Hide resolved
</thead>
<tbody>
<tr><td>Mamitiana</td><td>23</td><td>Madagascar</td></tr>
<tr><td>Yuki</td><td>48</td><td>Japan</td></tr>
</tbody>
</table>

```

#### CSS

```css
td {
padding: 0.125rem 0.5rem;
height: 3rem;
border: 1px solid black;
}

tbody > tr > td:nth-child(1) {
estelle marked this conversation as resolved.
Show resolved Hide resolved
text-align: left;
vertical-align: bottom;
background-color: silver;
}

tbody tr td:nth-child(2) {
estelle marked this conversation as resolved.
Show resolved Hide resolved
estelle marked this conversation as resolved.
Show resolved Hide resolved
text-align: center;
vertical-align: middle;
}

tbody tr td:nth-child(3) {
estelle marked this conversation as resolved.
Show resolved Hide resolved
estelle marked this conversation as resolved.
Show resolved Hide resolved
text-align: right;
vertical-align: top;
background-color: tomato;
}
```

#### Result

{{EmbedLiveSample('Styling_a_table_column', 100, 200)}}

## Specifications

{{Specifications}}
Expand Down