HTML/CSS/Table Style/table size

Материал из Web эксперт
Перейти к: навигация, поиск

Adding auto width to a Table

   <source lang="html4strict">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

                     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

   <head>
       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
       <title>Auto width on tables</title>
       <style type="text/css">
           table {
               width: auto;
               background: black;
               color: red;
           }
       </style>
   </head>
   <body>
<tbody> </tbody>
How will this table react to auto width?
   </body>

</html>

</source>
   
  


Column width

   <source lang="html4strict">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

                     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

   <head>
       <title>table-layout</title>
       <style rel="stylesheet" type="text/css">

body {

   font-family: sans-serif;

} table {

   border: 1px solid black;
   caption-side: bottom;
   width: 200px;
   table-layout: fixed;

} th {

   background: lightyellow;

} th, td {

   border: 1px solid black;
   padding: 5px;
   overflow: hidden;

} col#album {

   width: 200px;
   background: red;
   color: crimson;

} col#released {

   width: 1%;
   background: pink;

} div#control {

   width: 200px;
   background: crimson;
   color: white;
   text-align: center;
   font-family: monospace;
   margin-bottom: 5px;
   padding: 3px 0;

}

       </style>
   </head>
   <body>
           < -- 200 pixels -- >
<colgroup> <col id="album" /> <col id="artist" /> <col id="released" /> </colgroup> <thead> </thead> <tbody> </tbody>
My favorite records.
album artist released
R AAA 1965
B V 1967
M T 1995
   </body>

</html>

</source>
   
  


Column Width: percentage, auto and px

   <source lang="html4strict">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"> <head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8" />
   <title></title>

<style type="text/css" media="Screen">

  • .i {
 background-color: pink;

}

  • .a {
 width: auto;

}

  • .b {
 width: 75px;

}

  • .c {
 width: 150px;

}

  • .d {
 width: 10%;

}

  • .e {
 width: 50%;

} </style> </head> <body>

auto auto auto auto auto
auto 75px 75px 75px 75px
auto auto 150px 150px 150px
auto auto auto 10% 10%
auto auto auto auto 50%

</body> </html>

</source>
   
  


Fixed Table

   <source lang="html4strict">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"> <head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8" />
   <title></title>

<style type="text/css" media="Screen">

  • .fixed-layout {
 table-layout: fixed;

} </style> </head> <body>

autoauto

</body> </html>

</source>
   
  


Fixed Table Sized Columns

   <source lang="html4strict">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"> <head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8" />
   <title></title>

<style type="text/css" media="Screen">

  • .fixed-layout {
 table-layout: fixed;
 background: pink;

}

  • .sized1 {
 width: 200px;

}

  • .min-width1 {
 width: 1px;

}

</style> </head> <body>

200px 300px

</body> </html>

</source>
   
  


Fixed Table with fixed width

   <source lang="html4strict">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"> <head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8" />
   <title></title>

<style type="text/css" media="Screen">

  • .fixed-layout {
 table-layout: fixed;

}

  • .size3 {
 width: 100px;
 background: red;

}

  • .size4 {
 width: 300px;
 background: gold;

} </style> </head> <body>

100px 300px

</body> </html>

</source>
   
  


Maximum-width Sized Columns

   <source lang="html4strict">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"> <head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8" />
   <title></title>

<style type="text/css" media="Screen">

  • .auto-layout {
 table-layout: auto;

}

  • .sized1 {
 width: 200px;

}

  • .shrinkwrapped {
 width: auto;
 background: yellow;

}

</style> </head> <body>

200px300px

</body> </html>

</source>
   
  


Minimum-width Sized Columns

   <source lang="html4strict">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"> <head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8" />
   <title></title>

<style type="text/css" media="Screen">

  • .fixed-layout {
 table-layout: fixed;
 background: pink;

}

  • .min-width2 {
 width: 700px;

}

  • .sized1 {
 width: 200px;

} </style> </head> <body>

200px 300px

</body> </html>

</source>
   
  


Shrinkwrapped Table

   <source lang="html4strict">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"> <head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8" />
   <title></title>

<style type="text/css" media="Screen">

  • .auto-layout {
 table-layout: auto;

}

  • .shrinkwrapped {
 width: auto;
 background: pink;

}

  • .size1 {
 width: 1000px;
 background: gray;

}

  • .size2 {
 width: 3000px;
 background: menu;

} </style> </head> <body>

1000px 3000px

</body> </html>

</source>
   
  


Shrinkwrapped Table column width

   <source lang="html4strict">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"> <head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8" />
   <title></title>

<style type="text/css" media="Screen">

  • .auto-layout {
 table-layout: auto;

}

  • .shrinkwrapped {
 width: auto;
 background: yellow;

}

  • .sized1 {
 width: 200px;

}

</style> </head> <body>

200px 300px


</body> </html>

</source>
   
  


Sized or Stretched Table

   <source lang="html4strict">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"> <head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8" />
   <title></title>

<style type="text/css" media="Screen">

  • .auto-layout {
 table-layout: auto;

}

  • .sized {
 width: 700px;
 background: red;

}

  • .stretched {
 width: 100%;
 background: gold;

}

  • .size3 {
 width: 100px;

}

  • .size4 {
 width: 300px;

} </style> </head> <body>

100px 300px

</body> </html>

</source>
   
  


Sized Table

   <source lang="html4strict">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"> <head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8" />
   <title></title>

<style type="text/css" media="Screen">

  • .auto-layout {
 table-layout: auto;

}

  • .sized {
 width: 350px;

} </style> </head> <body>

Sized Table

autoauto

</body> </html>

</source>
   
  


Stretched Table

   <source lang="html4strict">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"> <head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8" />
   <title></title>

<style type="text/css" media="Screen">

  • .auto-layout {
 table-layout: auto;

}

  • .stretched {
 width: 100%;

} </style> </head> <body>

autoauto

</body> </html>

</source>
   
  


table auto width and height

   <source lang="html4strict">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

   <html>
       <head>
           <title></title>
           <style type="text/css">
               table {
           border: thin solid black;
           width: auto;
           height: auto;
       }
           </style>
       </head>
       <body>
                 The table only expands enough for the content inside of it.
       </body>
   </html>
</source>
   
  


Table border and cell border

   <source lang="html4strict">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

                     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

   <head>
       <title>table-layout</title>
       <style rel="stylesheet" type="text/css">

body {

   font-family: sans-serif;

} table {

   border: 1px solid black;
   caption-side: bottom;
   width: 200px;

} th {

   background: lightyellow;

} th, td {

   border: 1px solid red;
   padding: 5px;

} div#control {

   width: 200px;
   background: crimson;
   color: white;
   text-align: center;
   font-family: monospace;
   margin-bottom: 5px;
   padding: 3px 0;

}

       </style>
   </head>
   <body>
           < -- 200 pixels -- >
<colgroup> <col id="album" /> <col id="artist" /> <col id="released" /> </colgroup> <thead> </thead> <tbody> </tbody>
My favorite records.
album artist released
R AAA 1965
B V 1967
M T 1995
   </body>

</html>

</source>
   
  


table width: 100%

   <source lang="html4strict">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

                     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

   <head>
       <title>columns</title>
       <style rel="stylesheet" type="text/css">

body {

   font-family: sans-serif;

} table {

   border: 1px solid black;
   caption-side: bottom;
   width: 100%;

} th {

   background: lightyellow;

} th, td {

   border: 1px solid red;
   padding: 5px;

} col#album {

   width: 200px;
   background: pink;
   color: crimson;

} col#released {

   width: 1%;
   background: gold;

}

       </style>
   </head>
   <body>
<colgroup> <col id="album" /> <col id="artist" /> <col id="released" /> </colgroup> <thead> </thead> <tbody> </tbody>
My favorite records.
album artist released
R AAA 1965
B V 1967
M T 1995
   </body>

</html>

</source>
   
  


Table width: auto

   <source lang="html4strict">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"> <head>

   <meta http-equiv="content-type" content="text/html; charset=utf-8" />
   <title></title>

<style type="text/css" media="Screen">

  • .auto-layout {
 table-layout: auto;

}

  • .shrinkwrapped {
 width: auto;

} </style> </head> <body>

Shrinkwrapped Table

autoauto

</body> </html>

</source>