zoukankan      html  css  js  c++  java
  • 3个简单的页面布局示例

    本文内容:

      1.利用HTML5及float布局

      2.利用inline block布局

      3.利用CSS表格(table)布局


                      示例代码 -1 (利用HTML5标签及浮动布局)

    1. <style>
    2. header nav ul {
    3. margin:15px;
    4. list-style: none;
    5. height:50px;
    6. }
    7. header nav ul li {
    8. font-size:1.5em;
    9. color: coral;
    10. margin:10px;
    11. float: left;
    12. }
    13. header nav ul li a {
    14. text-decoration: none;
    15. }
    16. aside {
    17. margin-right:50px;
    18. float: left;
    19. width:200px;
    20. }
    21. aside ul {
    22. list-style: none;
    23. }
    24. article {
    25. float: left;
    26. }
    27. footer {
    28. font-family:Arial;
    29. clear: both;
    30. text-align: center;
    31. }
    32. </style>
    33. <!--定义页眉-->
    34. <header>
    35. <nav>
    36. <ul>
    37. <li><ahref="#">主链接一</a></li>
    38. <li><ahref="JavaScript:void (0)">主链接二</a></li>
    39. <li><aonclick="return false"href="index.html">主链接三</a></li>
    40. </ul>
    41. </nav>
    42. </header>
    43. <hr/>
    44. <!--定义左边侧栏导航-->
    45. <aside>
    46. <ul>
    47. <li>左侧导航栏链接1</li>
    48. <li>左侧导航栏链接2</li>
    49. </ul>
    50. </aside>
    51. <!--定义右边内容显示区-->
    52. <article>
    53. <section>
    54. <h2>主题内容标题1</h2>
    55. <p>
    56. ......
    57. </p>
    58. </section>
    59. <section>
    60. <h2>主题内容标题2</h2>
    61. <p>
    62. .......
    63. </p>
    64. </section>
    65. <section>
    66. <h2>主题内容标题3</h2>
    67. <p>
    68. .......
    69. </p>
    70. </section>
    71. </article>
    72. <!--定义页脚-->
    73. <footer>
    74. <hr/>
    75. <!--footer的样式设置为clear:both,以便使其始终居于底部,并占满整行。-->
    76. &copy;Jener_Yan <spanid="DateSpan"></span>
    77. </footer>
    78. <script>
    79. /*获取当前年份*/
    80. var d = document.getElementById("DateSpan");
    81. varNowYear=newDate();
    82. d.innerHTML =NowYear.getFullYear();
    83. </script>
    网页效果图
    注意点:浮动的设置
    ******************************************************************************************************
     
                   示例代码 -2 (利用inline block布局)
    1. <style>
    2. body {
    3. text-align: center;
    4. }
    5. div {
    6. display:inline-block;
    7. min-height:200px;
    8. padding:5px;
    9. margin:0;
    10. }
    11. header, footer {
    12. background-color: aquamarine;
    13. padding:5px;
    14. margin:5px;
    15. }
    16. main {
    17. width:100%;
    18. margin:0;
    19. }
    20. #main-l {
    21. background-color: chartreuse;
    22. width:20%;
    23. }
    24. #main-m {
    25. background-color: bisque;
    26. width:50%;
    27. /*此处的宽度占比不取60%是因为,还得留些空间给内边距(Padding)和外边距(Margin)*/
    28. }
    29. #main-r {
    30. background-color: coral;
    31. width:20%;
    32. }
    33. </style>
    34. <h2>inline block布局</h2>
    35. <header>
    36. header
    37. </header>
    38. <main>
    39. <divid="main-l">左侧栏宽 20%</div>
    40. <divid="main-m">中部栏宽 50%</div>
    41. <divid="main-r">右侧栏宽 20%</div>
    42. </main>
    43. <footer>&copy;Jener_Yan &nbsp;<spanid="DateSpan"></span></footer>
    44. <script>
    45. /*获取当前年份*/
    46. var d = document.getElementById("DateSpan");
    47. varNowYear=newDate();
    48. d.innerHTML =NowYear.getFullYear();
    49. </script>
    网页效果图
    注意点:width中对margin的预留空间。
    ******************************************************************************************************
                   示例代码 -3 (利用CSS表格式布局)
    示例代码
    1. <style>
    2. /*全局设置*/
    3. div {
    4. min-height:100px;
    5. margin:0auto;
    6. padding:6px;
    7. }
    8. header, footer {
    9. padding:3px;
    10. background-color: darkgray;
    11. margin:4px0;
    12. width:100%;
    13. }
    14. .container {
    15. text-align: center;
    16. }
    17. .content {
    18. display: table;
    19. /*将div转化为表格模式显示*/
    20. width:100%;
    21. }
    22. /*上部三个栏目*/
    23. .upContent {
    24. display: table-row;
    25. /*将div转换为行显示*/
    26. }
    27. .upContentL {
    28. background-color:#fffefe;
    29. width:20%;
    30. display: table-cell;
    31. /*将div转化为单元格显示*/
    32. }
    33. .upContentM {
    34. background-color: aqua;
    35. width:60%;
    36. display: table-cell;
    37. }
    38. .upContentR {
    39. display: table-cell;
    40. background-color: skyblue;
    41. width:20%;
    42. }
    43. /*下部两个栏目*/
    44. .downContent {
    45. display: table-row;
    46. width:100%;
    47. }
    48. .downContentL {
    49. background-color: aquamarine;
    50. display: table-cell;
    51. width:30%;
    52. }
    53. .downContentR {
    54. background-color: lightcyan;
    55. width:70%;
    56. display: table-cell;
    57. }
    58. </style>
    59. <divclass="container">
    60. <h2>
    61. CSS表格式布局
    62. </h2>
    63. <header>
    64. header
    65. </header>
    66. <divclass="content">
    67. <divclass="upContent">
    68. <divclass="upContentL">上部左栏 20%</div>
    69. <divclass="upContentM">上部中栏 60%</div>
    70. <divclass="upContentR">上部右栏 20%</div>
    71. </div>
    72. </div>
    73. <divclass="content">
    74. <divclass="downContent">
    75. <divclass="downContentL">下部左栏 20%</div>
    76. <divclass="downContentR">下部右栏 80%</div>
    77. </div>
    78. </div>
    79. <footer>&copy;Jener_Yan &nbsp;<spanid="DateSpan"></span></footer>
    80. </div>
    81. <script>
    82. var date =newDate();
    83. document.getElementById("DateSpan").innerHTML = date.getFullYear();
    84. </script>
    网页效果图
    注意点:采用表格式布局注意显示(display)属性值的设置,table → table-row → table-cell 





    从零到现在,一路走来,感谢众多无私的知识分享者,我愿意为你们接下一棒!
  • 相关阅读:
    Oracle表空间管理
    Oracle创建函数
    Oracle触发器
    Oracle概要文件
    Oracle结构控制语句
    比较实用的网站
    Java23种设计模式之单例模式
    Java 对象属性的遍历
    JQuery 多个ID对象绑定一个click事件
    好习惯的养成****
  • 原文地址:https://www.cnblogs.com/Jener/p/5799466.html
Copyright © 2011-2022 走看看