Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2536725
  • 博文数量: 245
  • 博客积分: 4125
  • 博客等级: 上校
  • 技术积分: 3113
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-25 23:56
文章分类

全部博文(245)

文章存档

2015年(2)

2014年(26)

2013年(41)

2012年(40)

2011年(134)

2010年(2)

分类: 系统运维

2011-09-22 16:54:55


From:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2.     "">

  3. <html xmlns="" xml:lang="en">
  4. <head>
  5.     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  6.     <title>CSS Layout - 100% height</title>
  7.     <link rel="stylesheet" type="text/css" href="css/layout1.css" />
  8. </head>
  9. <body>

  10.     <div id="container">

  11.         <div id="header">
  12.             <h1>CSS layout: 100% height with header and footer</h1>
  13.             <p>Sometimes things that used to be really simple with tables can still appear pretty hard with CSS. This layout for instance would consist of 3 cells; two with a fixed height, and a third one in the center filling up the remaining space. Using CSS, however, you have to take a different approach.</p>
  14.         </div>

  15.         <div id="content">
  16.             <h2>Min-height</h2>
  17.             <p>
  18.                 The #container element of this page has a min-height of 100%. That way, if the content requires more height than the viewport provides, the height of #content forces #container to become longer as well. Possible columns in #content can then be visualised with a background image on #container; divs are not table cells, and you don't need (or want) the fysical elements to create such a visual effect. If you're not yet convinced; think wobbly lines and gradients instead of straight lines and simple color schemes.
  19.             </p>
  20.             <h2>Relative positioning</h2>
  21.             <p>
  22.                 Because #container has a relative position, #footer will always remain at its bottom; since the min-height mentioned above does not prevent #container from scaling, this will work even if (or rather especially when) #content forces #container to become longer.
  23.             </p>
  24.             <h2>Padding-bottom</h2>
  25.             <p>
  26.                 Since it is no longer in the normal flow, padding-bottom of #content now provides the space for the absolute #footer. This padding is included in the scrolled height by default, so that the footer will never overlap the above content.
  27.             </p>
  28.             <p>
  29.                 Scale the text size a bit or resize your browser window to test this layout. The <a href="css/layout1.css">CSS file is over here</a>.
  30.             </p>
  31.             <p>
  32.                 <a href="../css.html">Back to CSS Examples</a>
  33.             </p>
  34.         </div>

  35.         <div id="footer">
  36.             <p>
  37.                 This footer is absolutely positioned to bottom:0; of #container. The padding-bottom of #content keeps me from overlapping it when the page is longer than the viewport.
  38.             </p>
  39.         </div>
  40.     </div>


  41.     <script src="" type="text/javascript"></script>
  42.     <script type="text/javascript">
  43.         _uacct = "UA-472607-1"; urchinTracker();
  44.     </script>

  45. </body>

  1. /**
  2.  * 100% height layout with header and footer
  3.  * ----------------------------------------------
  4.  * Feel free to copy/use/change/improve
  5.  */

  6. html,body {
  7.     margin:0;
  8.     padding:0;
  9.     height:100%; /* needed for container min-height */
  10.     background:gray;
  11.     
  12.     font-family:arial,sans-serif;
  13.     font-size:small;
  14.     color:#666;
  15. }

  16. h1 {
  17.     font:1.5em georgia,serif;
  18.     margin:0.5em 0;
  19. }

  20. h2 {
  21.     font:1.25em georgia,serif;
  22.     margin:0 0 0.5em;
  23. }
  24.     h1, h2, a {
  25.         color:orange;
  26.     }

  27. p {
  28.     line-height:1.5;
  29.     margin:0 0 1em;
  30. }

  31. div#container {
  32.     position:relative; /* needed for footer positioning*/
  33.     margin:0 auto; /* center, not in IE5 */
  34.     width:750px;
  35.     background:#f0f0f0;
  36.     
  37.     height:auto !important; /* real browsers */
  38.     height:100%; /* IE6: treaded as min-height*/

  39.     min-height:100%; /* real browsers */
  40. }

  41. div#header {
  42.     padding:1em;
  43.     background:#ddd url("../csslayout.gif") 98% 10px no-repeat;
  44.     border-bottom:6px double gray;
  45. }
  46.     div#header p {
  47.         font-style:italic;
  48.         font-size:1.1em;
  49.         margin:0;
  50.     }

  51. div#content {
  52.     padding:1em 1em 5em; /* bottom padding for footer */
  53. }
  54.     div#content p {
  55.         text-align:justify;
  56.         padding:0 1em;
  57.     }

  58. div#footer {
  59.     position:absolute;
  60.     width:100%;
  61.     bottom:0; /* stick to bottom */
  62.     background:#ddd;
  63.     border-top:6px double gray;
  64. }
  65.     div#footer p {
  66.         padding:1em;
  67.         margin:0;
  68.     }

再一个表单模板
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2.     "">

  3. <html xmlns="" xml:lang="en">
  4. <head>
  5.     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  6.     <title>CSS and tables for forms</title>
  7.     <link rel="stylesheet" type="text/css" href="css/sample1.css" />
  8. </head>
  9. <body>

  10.     <div id="container">
  11.         <div id="header">
  12.             <h1>CSS and tables for forms</h1>
  13.             <p>We don't always get to design our own form layouts. The form below, for instance, looks more suited for print than for the web, but that's just the way things sometimes go.</p>
  14.         </div>

  15.         <div id="content">
  16.             <h2>Widht:100%</h2>
  17.             <p>
  18.                 Instead of setting the width for each individual form element, why not simply let them scale to a grid automatically? The form below does exactly that. A fixed table layout creates a solid grid to work with. This grid is then used with varying colspan values, and the 100% width for input fields does the rest.
  19.             </p>

  20.             <table>
  21.                 <tr>
  22.                     <th>First name:</th>
  23.                     <td colspan="3"><input type="text" /></td>
  24.                 </tr>
  25.                 <tr class="required">
  26.                     <th>Last name:</th>
  27.                     <td colspan="3"><input type="text" /></td>
  28.                 </tr>
  29.                 <tr>
  30.                     <th>Gender:</th>
  31.                     <td colspan="3" class="input-group required">
  32.                         <input type="radio"> Male
  33.                         <input type="radio"> Female
  34.                     </td>
  35.                 </tr>
  36.                 <tr class="required">
  37.                     <th>Address:</th>
  38.                     <td colspan="3"><input type="text" /></td>
  39.                 </tr>
  40.                 <tr class="required">
  41.                     <th>House number:</th>
  42.                     <td><input type="text" /></td>
  43.                     <th>Postal code:</th>
  44.                     <td><input type="text" /></td>
  45.                 </tr>
  46.                 <tr>
  47.                     <th>E-mail address:</th>
  48.                     <td colspan="2" class="required"><input type="text" /></td>
  49.                     <td class="input-group">
  50.                         <input type="checkbox"/> Newsletter?
  51.                     </td>
  52.                 </tr>
  53.                 <tr>
  54.                     <th>Phone number:</th>
  55.                     <td colspan="2" class="required"><input type="text" /></td>
  56.                     <td class="input-group">
  57.                         <input type="checkbox"/> call me now
  58.                     </td>
  59.                 </tr>
  60.                 <tr>
  61.                     <th>Fax number:</th>
  62.                     <td colspan="3"><input type="text" /></td>
  63.                 </tr>
  64.             </table>

  65.             <p>
  66.                 Granted, using tables for forms may be questionable, but you're entering a world of pain if you don't do it for complex form layouts. The <a href="css/sample1.css">CSS file is over here</a>.
  67.             </p>
  68.             <p>
  69.                 <a href="../css.html">Back to CSS Examples</a>
  70.             </p>

  71.         </div>
  72.     </div>

  73.     <script src="" type="text/javascript"></script>
  74.     <script type="text/javascript">
  75.         _uacct = "UA-472607-1"; urchinTracker();
  76.     </script>


  77. </body>
  78. </html>


  1. /**
  2.  * 100% height layout with header and footer
  3.  * ----------------------------------------------
  4.  * Feel free to copy/use/change/improve
  5.  */


  6. table {
  7.     table-layout:fixed; /* force a solid grid */
  8.     border-collapse:collapse;
  9.     margin: 0 auto 1em;
  10.     width:450px;
  11. }
  12.     table th, table td {
  13.         white-space:nowrap; /* don't want wrapping text */
  14.         padding:2px 20px 2px 5px; /* right padding for required field marker */
  15.     }

  16.     table th {
  17.         padding:2px 0 2px 5px;
  18.         text-align:right;
  19.     }

  20.     td.required, tr.required td {
  21.         background:url("../req.gif") center right no-repeat;
  22.     }

  23.     table input {
  24.         width:100%; /* simply scale inputs to table cell size */
  25.     }
  26.         td.input-group input {
  27.             width:auto; /* but not for radios or checks */
  28.         }




  29. /* Other css */

  30. html,body {
  31.     margin:0;
  32.     padding:0;
  33.     height:100%;
  34.     background:gray;
  35.     
  36.     font-family:arial,sans-serif;
  37.     font-size:small;
  38.     color:#666;
  39. }

  40. h1 {
  41.     font:1.5em georgia,serif;
  42.     margin:0.5em 0;
  43. }

  44. h2 {
  45.     font:1.25em georgia,serif;
  46.     margin:0 0 0.5em;
  47. }
  48.     h1, h2, a {
  49.         color:orange;
  50.     }

  51. p {
  52.     line-height:1.5;
  53.     margin:0 0 1em;
  54. }

  55. div#container {
  56.     margin:0 auto;
  57.     width:750px;
  58.     background:#f0f0f0;
  59.     height:auto !important;
  60.     height:100%;
  61.     min-height:100%;
  62. }

  63. div#header {
  64.     padding:1em;
  65.     background:#ddd url("../csslayout.gif") 98% 10px no-repeat;
  66.     border-bottom:6px double gray;
  67. }
  68.     div#header p {
  69.         font-style:italic;
  70.         font-size:1.1em;
  71.         margin:0;
  72.     }

  73. div#content {
  74.     padding:1em;
  75. }
  76.     div#content p {
  77.         text-align:justify;
  78.         padding:0 1em;
  79.     }

阅读(1348) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~