-
Notifications
You must be signed in to change notification settings - Fork 90
Add post 35 - html button structured using a html table #199
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| --- | ||
| title: "#35 a perfectly structured button" | ||
| date: 2025-09-11 | ||
| permalink: /{{ title | slug }}/index.html | ||
| layout: layouts/entry.njk | ||
| author: annedrtlf | ||
| badcode: "<button type=\"button\" onclick=\"window.open('https://example.com/other-page')\"> | ||
| <table><tbody><tr><td><i class=\"fa fa-arrow-left\" aria-hidden=\"true\"></i></td><td align=\"left\">Back</td></tr></tbody></table> | ||
| </button>" | ||
| goodcode: "<button type=\"button\" style=\"padding: 12px 16px;\" onclick=\"window.open('https://example.com/other-page')\"><i class=\"fa fa-arrow-left\" aria-hidden=\"true\"></i>Back</button>" | ||
| --- | ||
|
|
||
| <div class="section bad"> | ||
|
|
||
| ## Bad code | ||
|
|
||
| ```html | ||
| {{ badcode | pretty }} | ||
| ``` | ||
| </div> | ||
| <button type="button" onclick="window.open('example.com/other-page')"> | ||
| <table> | ||
| <tbody> | ||
| <tr> | ||
| <td><i class="fa fa-arrow-left" aria-hidden="true"></i></td> | ||
| <td align="left">Back</td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
| </button> | ||
| <div class="section" id="issues"> | ||
|
|
||
| ## Issues and how to fix them | ||
|
|
||
| 1. Technically it works to put a table inside a button. As the buttons content is representational the syntax is valid. Nevertheless it adds complexity to the code and is not needed. | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean presentational? If yes, please link the term. Accessible Rich Internet Applications (WAI-ARIA) 1.2 Here you say that the syntax is valid. Later you say the opposite. I would split up your points differently. Here's a quick and dirty short version.
|
||
| 1. Based on the [MDN content categories](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories) a table is not allowed inside a button. As the table qualifies as flow content and the button accepts phrasing content only. | ||
|
|
||
| 1. Keep it simple and structure the button using CSS. | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would mention Flexbox here as a suitable technique |
||
| 1. If necessary structure buttons using phrasing content such as `<i>` and `<span>` | ||
dpm-anne-kd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| </div> | ||
|
|
||
| <div class="section"> | ||
|
|
||
| ## Good code | ||
|
|
||
| ```html | ||
| {{ goodcode | pretty }} | ||
| ``` | ||
| </div> | ||
|
|
||
| <div class="section"> | ||
|
|
||
| <h2 id="resources">Resources</h2> | ||
|
|
||
| - [`<button>` on MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button) | ||
| - [`<table>` on MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table) | ||
| - [Content categories on MDN](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories) | ||
| - [Buttons Role on W3C](https://w3c.github.io/aria/#button) | ||
| - [`<button>` on W3Schools](https://www.w3schools.com/tags/tag_button.asp) | ||
| - [`<table>` on W3Schools](https://www.w3schools.com/tags/tag_table.asp) | ||
|
|
||
| </div> | ||
Uh oh!
There was an error while loading. Please reload this page.