Help:Table/Width: Difference between revisions

Content deleted Content added
CSS max-width on table as a whole: Works on both desktop and mobile.
 
(29 intermediate revisions by 3 users not shown)
Line 1:
__TOC__
 
See the '''[[Help:Table#Width|Width]]''' section of [[Help:Table]]. ThisTo examplesummarize, table'''max-width''' needsis tothe bepreferred onway thisto separatelimit pagewidths inon ordertables. toIt testworks iton moredivs easilytoo. inNote narrowerthough browser windows. Test itthat in both desktoptables and mobiledivs viewsthere (onneeds cellto phonesbe spaces in portraitlong orientation).lines Seeof the mobiletext or desktopwikitext. viewOtherwise linkthere atis theno bottompoint ofat thiswhich Wikipedia page. Use a cell phone to get thethat trueline mobilecan viewwrap.
 
These example tables need to be on this separate page in order to test them more easily in narrower browser windows. Test them in both desktop and mobile views (on cell phones in portrait orientation). See the mobile or desktop view link at the bottom of this Wikipedia page. Use a cell phone to get the true mobile view.
In desktop view narrow your browser window. Note that the first table narrows along with the browser window. The second table does not, and it needs the horizontal scrollbar to see all of the table.
 
In desktop view on a PC '''narrow your browser window.''' On a Wikipedia page that has '''only text (no tables)''' a '''horizontal scrollbar''' will show up '''well before the text is unable to wordwrap further.''' For example see '''[[User:Timeshifter/Sandbox204|this sandbox]].'''
On Wikipedia CSS width settings in any table cell (header or data) are treated more like a max-width setting, and the table narrows as the browser window narrows.
 
== Line breaks ==
A CSS width setting for the overall table in desktop view acts like width settings on divs and tables on webpages outside Wikipedia. Horizontal scrollbars are created when narrowed enough. See width outside Wikipedia:
*[https://www.w3schools.com/cssref/pr_dim_width.php CSS width Property].
 
Line breaks '''<nowiki><br></nowiki>''' are OK to narrow header cells, and other cells. See Graham87 comments at [[Help talk:Table/Advanced#Line breaks in table cells]].
In mobile view on Wikipedia width and max-width settings on the table as a whole are ignored altogether. In mobile view all the tables below narrow without forming horizontal scrollbars. This is different from tables on webpages outside Wikipedia. Overall table widths (as opposed to max-widths) do not narrow on most pages outside Wikipedia. See max-width outside Wikipedia:
*[https://www.w3schools.com/css/css_dimension.asp CSS Height, Width and Max-width].
 
== Soft hyphens ==
Experiment with em and other width settings on another page outside Wikipedia:
*[https://www.w3schools.com/html/html_table_sizes.asp HTML Table Sizes].
 
'''{{tlx|shy}}''' can be placed in long header words like "population" to add a [[soft hyphen]] when the screen is narrow (as on portrait view on cell phones):
== CSS width on table cell ==
;Wikitext
:<code><nowiki>popu{{shy}}lation</nowiki></code>
;Which appears as
: population
;Except in narrow screens where it looks like this:
:popu-<br>lation
 
== CSS max-width on table as a whole ==
CSS width for table header cell acts like a max-width setting on desktop, and so it shrinks as browser window shrinks. It shrinks proportionally on mobile, too. No scrollbar in either mode.
{{hatnote|'''Note:''' "Lorem ipsum ..." is from [https://www.lipsum.com here].}}
CSS max-width for overall table width '''works on both desktop and mobile.''' And it shrinks further as screen or browser narrows. Portrait versus landscape view on cell phone.
 
''';Overall table width attempted via max-width:'''
'''Center header width setting:'''
:<code>!{| Left !!class=wikitable style="max-width:40em | Center !! Right;"</code>
 
{| class=wikitable style="max-width:40em;"
|-
! Left !! Center !! Right
|-
| BottomTop left cell || BottomTop center cell || BottomTop right cell
|-
| Middle left cell || Middle center cell || Middle right cell
|-
| Bottom left cell || Bottom center cell || "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."
|}
 
== CSS max-width on table header cells ==
 
See examples at [[Help:Table#Width]].
 
== CSS max-width on a table cell ==
 
CSS max-width for a table cell '''works on both desktop and mobile.''' And it shrinks further as screen or browser narrows. Portrait versus landscape view on cell phone.
 
:<code>| Bottom left cell || Bottom center cell || style=max-width:40em; |"Lorem ipsum ...</code>
 
{| class=wikitable
|-
! Left !! style=width:40em | Center !! Right
|-
| Top left cell || Top center cell || Top right cell
Line 31 ⟶ 57:
| Middle left cell || Middle center cell || Middle right cell
|-
| Bottom left cell || Bottom center cell || style=max-width:40em; |"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."
| Bottom left cell || Bottom center cell || Bottom right cell
|}
 
== CSS width onsetting tablefor asthe aoverall wholetable ==
 
A CSS width setting for the overall table in '''desktop view''' acts like width workssettings on desktopdivs and tables on webpages outside Wikipedia. A '''horizontal (scrollbar''' ifis narrowcreated enough),when andthe screen is ignoredtoo altogethernarrow onfor mobilethe width setting. See width outside Wikipedia:
*[https://developer.mozilla.org/en-US/docs/Web/CSS/width width - CSS: Cascading Style Sheets | MDN]
*[https://www.w3schools.com/cssref/pr_dim_width.php CSS width Property].
 
In '''mobile view''' on Wikipedia width and max-width settings on the table as a whole are '''ignored altogether''' for the most part (see next section). In mobile view all the tables below narrow without forming horizontal scrollbars. This is different from tables on webpages outside Wikipedia. Overall table widths (as opposed to max-widths) do not narrow on most pages outside Wikipedia. See max-width outside Wikipedia:
*[https://www.w3schools.com/css/css_dimension.asp CSS Height, Width and Max-width].
 
Experiment with em and other width settings on another page outside Wikipedia:
*[https://www.w3schools.com/html/html_table_sizes.asp HTML Table Sizes].
 
== Example. CSS width on table as a whole ==
 
CSS width for overall table width works on desktop ('''horizontal scrollbar''' if screen is too narrow for width setting). It is ignored altogether on these iPhone browsers: Edge, Chrome, Firefox, Opera. But not on iPhone Safari where it works the same as on desktop.
 
''';Overall table width:'''
:<code>{| class=wikitable style=width:50em</code>
 
Line 52 ⟶ 90:
|}
 
== CSS max-width on table asheader a wholecell ==
 
CSS max-width for overalla table widthheader workscell onacts bothlike desktopa andmax-width mobilesetting. AndSo it shrinks further as screen or browser narrowswindow shrinks. PortraitIt versusshrinks landscape viewproportionally on cellmobile, too. No horizontal scrollbar in either phonemode.
 
''';Center header width setting:'''
'''Overall table width attempted via max-width:'''
:<code>{|! class=wikitableLeft !! style="max-width:40em;" | Center !! Right</code>
 
{| class=wikitable style="max-width:40em;"
|-
! Left !! style=width:40em | Center !! Right
|-
| Top left cell || Top center cell || Top right cell
Line 67 ⟶ 105:
| Middle left cell || Middle center cell || Middle right cell
|-
| Bottom left cell || Bottom center cell || Bottom right cell
| Bottom left cell || Bottom center cell || "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."
|}