Help:Table/Width: Difference between revisions

Content deleted Content added
CSS max-width does not work for overall table width
 
(38 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. in narrower browser windows.Note Testthough itthat in both desktoptables and mobiledivs viewsthere (onneeds cellto be phonesspaces in portraitlong orientation).lines See theof mobiletext or desktopwikitext. Otherwise there is viewno linkpoint at thewhich bottomthat ofline thiscan Wikipediawrap. page.
 
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. Whereas 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.
 
== Line breaks ==
In mobile view all width settings are treated like max-width settings. Both tables below narrow without forming horizontal scrollbars. This is different from tables on webpages outside Wikipedia. Overall table widths do not narrow on most pages outside Wikipedia.
 
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]].
Experiment with various em and other width settings on these pages outside Wikipedia:
*[https://www.w3schools.com/html/html_table_sizes.asp HTML Table Sizes].
*[https://www.w3schools.com/css/css_dimension.asp CSS Height, Width and Max-width].
*[https://www.w3schools.com/cssref/pr_dim_width.php CSS width Property].
 
== CSSSoft width on table cellhyphens ==
 
'''{{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):
'''Center header width setting:'''
;Wikitext
:<code>! Left !! style=width:40em | Center !! Right</code>
:<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 ==
{{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:'''
:<code>{| class=wikitable style="max-width:50em40em;"</code>
 
{| class=wikitable style="max-width:50em40em;"
|-
! 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 27 ⟶ 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 settings on divs and tables on webpages outside Wikipedia. A '''horizontal scrollbar''' is created when the screen is too narrow for the width setting. See width outside Wikipedia:
'''Overall table width:'''
*[https://developer.mozilla.org/en-US/docs/Web/CSS/width width - CSS: Cascading Style Sheets | MDN]
:<code>{| class=wikitable style=width:40em</code>
*[https://www.w3schools.com/cssref/pr_dim_width.php CSS width Property].
 
In '''mobile view''' allon Wikipedia width settings on the table as a whole are treated'''ignored likealtogether''' max-widthfor settingsthe most part (see next section). BothIn 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 various em and other width settings on theseanother pagespage 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:40em50em</code>
 
{| class=wikitable style=width:40em50em
|-
! Left !! Center !! Right
Line 46 ⟶ 90:
|}
 
== CSS max-width doeson nottable workheader for overall table widthcell ==
 
CSS width for a table header cell acts like a max-width setting. So it shrinks as browser window shrinks. It shrinks proportionally on mobile, too. No horizontal scrollbar in either mode.
'''Overall table width attempted via max-width:'''
:<code>{| class=wikitable style="max-width:50em;"</code>
 
''';Center header width setting:'''
{| class=wikitable style="max-width:50em;"
:<code>! Left !! style=width:40em | Center !! Right</code>
 
{| class=wikitable
|-
! Left !! style=width:40em | Center !! Right
|-
| Top left cell || Top center cell || Top right cell