Difference between revisions of "User:RainSlide/CSS Boxes"
m (→float: left: modify desc) |
(Adjust styles) |
||
Line 29: | Line 29: | ||
<div style="display: table; background-color: #EFE; | <div style="display: table; background-color: #EFE; | ||
margin: .5em 0; padding: .5em 1em; border: 1px solid;"> | margin: .5em 0; padding: .5em 1em; border: 1px solid;">No problem for adaptive width.</div> | ||
No problem for adaptive width.</div> | |||
<div style="display: table; background-color: #EFE; | <div style="display: table; background-color: #EFE; | ||
margin: .5em 0; padding: .5em 1em; border: 1px solid;"> | margin: .5em 0; padding: .5em 1em; border: 1px solid;">No problem for floating siblings. | ||
No problem for floating siblings.< | <span style="display: block; opacity: .5; text-align: justify;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</span></div> | ||
</div> | </div> | ||
Line 42: | Line 41: | ||
|- | |- | ||
| <div style="display: table; background-color: #FEE; | | <div style="display: table; background-color: #FEE; | ||
margin: .5em 0; padding: .5em 1em; border: 1px solid;"> | margin: .5em 0; padding: .5em 1em; border: 1px solid;">No padding when it's in another table, however.</div> | ||
No padding when it's in another table, however.</div> | |||
|} | |} | ||
Line 54: | Line 52: | ||
<div style="display: table-cell; background-color: #EFE; | <div style="display: table-cell; background-color: #EFE; | ||
margin: .5em 0; padding: .5em 1em; border: 1px solid;"> | margin: .5em 0; padding: .5em 1em; border: 1px solid;">No problem for adaptive width.</div> | ||
No problem for adaptive width.</div> | |||
<p style="display: table; background-color: #FEE; padding: 0 1ch; border: 1px solid;">Table cells are not blocky! Without this sentence, they are in the same row by now.</p> | <p style="display: table; background-color: #FEE; padding: 0 1ch; border: 1px solid;">Table cells are not blocky! Without this sentence, they are in the same row by now.</p> | ||
<div style="display: table-cell; background-color: #EFE; | <div style="display: table-cell; background-color: #EFE; | ||
margin: .5em 0; padding: .5em 1em; border: 1px solid;"> | margin: .5em 0; padding: .5em 1em; border: 1px solid;">No problem for floating siblings. | ||
No problem for floating siblings.< | <span style="display: block; opacity: .5; text-align: justify;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</span></div> | ||
<p style="display: table; background-color: #FEE; padding: 0 1ch; border: 1px solid;">Table cells have no margin.</p> | <p style="display: table; background-color: #FEE; padding: 0 1ch; border: 1px solid;">Table cells have no margin.</p> | ||
Line 75: | Line 72: | ||
<div style="display: table-caption; background-color: #FEE; | <div style="display: table-caption; background-color: #FEE; | ||
margin: .5em 0; padding: .5em 1em; border: 1px solid;"> | margin: .5em 0; padding: .5em 1em; border: 1px solid;">No adaptive width.</div> | ||
No adaptive width.</div> | |||
<div style="display: table-caption; background-color: #FEE; | <div style="display: table-caption; background-color: #FEE; | ||
margin: .5em 0; padding: .5em 1em; border: 1px solid;"> | margin: .5em 0; padding: .5em 1em; border: 1px solid;">It's hiding. | ||
It's hiding.< | <span style="display: block; opacity: .5; text-align: justify;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</span></div> | ||
<p style="display: table; background-color: #FEE; padding: 0 1ch; border: 1px solid;">There can only be one table caption per table, or, per anything.</p> | <p style="display: table; background-color: #FEE; padding: 0 1ch; border: 1px solid;">There can only be one table caption per table, or, per anything.</p> | ||
Line 94: | Line 90: | ||
<div style="display: table-row; background-color: #EFE; | <div style="display: table-row; background-color: #EFE; | ||
margin: .5em 0; padding: .5em 1em; border: 1px solid;"> | margin: .5em 0; padding: .5em 1em; border: 1px solid;">No problem for adaptive width?</div> | ||
No problem for adaptive width?</div> | |||
<div style="display: table-row; background-color: #EFE; | <div style="display: table-row; background-color: #EFE; | ||
margin: .5em 0; padding: .5em 1em; border: 1px solid;"> | margin: .5em 0; padding: .5em 1em; border: 1px solid;">No problem for floating siblings? | ||
No problem for floating siblings?< | <span style="display: block; opacity: .5; text-align: justify;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</span></div> | ||
<p style="display: table; background-color: #FEE; padding: 0 1ch; border: 1px solid;">Table rows have no margin, padding or border.</p> | <p style="display: table; background-color: #FEE; padding: 0 1ch; border: 1px solid;">Table rows have no margin, padding or border.</p> | ||
Line 121: | Line 116: | ||
<div style="float: left; background-color: #EFE; | <div style="float: left; background-color: #EFE; | ||
margin: .5em 0; padding: .5em 1em; border: 1px solid;"> | margin: .5em 0; padding: .5em 1em; border: 1px solid;">No problem for adaptive width.</div> | ||
No problem for adaptive width.</div> | |||
<div style="float: left; background-color: #FEE; | <div style="float: left; background-color: #FEE; | ||
margin: .5em 0; padding: .5em 1em; border: 1px solid;"> | margin: .5em 0; padding: .5em 1em; border: 1px solid;">It falls off from its floating siblings. | ||
It falls off from its floating siblings.< | <span style="display: block; opacity: .5; text-align: justify;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</span></div> | ||
</div> | </div> | ||
Line 140: | Line 134: | ||
<div style="display: inline-block; background-color: #EFE; | <div style="display: inline-block; background-color: #EFE; | ||
margin: .5em 0; padding: .5em 1em; border: 1px solid;"> | margin: .5em 0; padding: .5em 1em; border: 1px solid;">No problem for adaptive width.</div> | ||
No problem for adaptive width.</div> | |||
<div style="display: inline-block; background-color: #FEE; | <div style="display: inline-block; background-color: #FEE; | ||
margin: .5em 0; padding: .5em 1em; border: 1px solid;"> | margin: .5em 0; padding: .5em 1em; border: 1px solid;">But inline blocks are inline.</div> | ||
But inline blocks are inline.</div> | |||
<div style="display: inline-block; background-color: #FEE; | <div style="display: inline-block; background-color: #FEE; | ||
margin: .5em 0; padding: .5em 1em; border: 1px solid;"> | margin: .5em 0; padding: .5em 1em; border: 1px solid;">It also falls off from its floating siblings. | ||
It also falls off from its floating siblings.< | <span style="display: block; opacity: .5; text-align: justify;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</span></div> | ||
</div> | </div> | ||
Line 159: | Line 151: | ||
<div style="display: flow-root; background-color: #FEE; | <div style="display: flow-root; background-color: #FEE; | ||
margin: .5em 0; padding: .5em 1em; border: 1px solid;"> | margin: .5em 0; padding: .5em 1em; border: 1px solid;">No adaptive width.</div> | ||
No adaptive width.</div> | |||
<div style="display: flow-root; background-color: #EFE; | <div style="display: flow-root; background-color: #EFE; | ||
margin: .5em 0; padding: .5em 1em; border: 1px solid;"> | margin: .5em 0; padding: .5em 1em; border: 1px solid;">No problem for floating siblings. | ||
No problem for floating siblings.< | <span style="display: block; opacity: .5; text-align: justify;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</span></div> | ||
</div> | </div> | ||
This is the end of part one. Part two will feature <code>contain: content</code>, <code>width: max-content</code>, <code>box-sizing: border-box; max-width: 100%</code>, <code>display: flex</code>, <code>display: grid</code>, and more, if I ever got time to work on the part two. | This is the end of part one. Part two will feature <code>contain: content</code>, <code>width: max-content</code>, <code>box-sizing: border-box; max-width: 100%</code>, <code>display: flex</code>, <code>display: grid</code>, and more, if I ever got time to work on the part two. |
Revision as of 05:11, 27 September 2021
This page is mainly for showing why Template:Hint, Template:Note and Template:Warning uses display: table
to archive compatibility for both adaptive width and floating sibling(s).
If a set of style is not compatible with adaptive width, it span to its full width even when it don't need to.
If a set of style is not compatible with floating sibling(s), the element may still work well with some short content in it; in another word, it may still looks fine when its content width + margin + padding + border is lower than the "remaining width" lefted by the floating sibling(s). So we have to use Lorem ipsum (as well as a floating box, for sure) to test it.
Ideally, you may just set the widths to fixed values, and pretend nothing happens and CSS is awesome. However, the content container of MediaWiki got adaptive width, and maybe you are maintaining a MediaWiki Template, with only inline styles.
is
Awesome
Table
display: table
This is a floating box.
This is a floating box.
This is a floating box.
This is a floating box.
This is a wikitable |
---|
No padding when it's in another table, however.
|
display: table-cell
This is a floating box.
This is a floating box.
This is a floating box.
This is a floating box.
Table cells are not blocky! Without this sentence, they are in the same row by now.
Table cells have no margin.
This is a floating box.
This is a floating box.
This is a floating box.
This is a floating box.
There can only be one table caption per table, or, per anything.
display: table-row
This is a floating box.
This is a floating box.
This is a floating box.
This is a floating box.
Table rows have no margin, padding or border.
Other table display values works like table rows, or won't even display its contents.
A new block formatting context
See guide Block formatting context on MDN.
float: left
Will everything go right with float set to left?
This is a floating box.
This is a floating box.
This is a floating box.
This is a floating box.
No, something falls down.
display: inline-block
This is a floating box.
This is a floating box.
This is a floating box.
This is a floating box.
display: flow-root
This is a floating box.
This is a floating box.
This is a floating box.
This is a floating box.
This is the end of part one. Part two will feature contain: content
, width: max-content
, box-sizing: border-box; max-width: 100%
, display: flex
, display: grid
, and more, if I ever got time to work on the part two.