Blogger Information
Blog 3
fans 0
comment 0
visits 1531
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
浮动定位与布局--PHP九期线上班
丁磊
Original
602 people have browsed it

制作一张商品信息表,内容自定,要求用到行与列的合并

HTML部分

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>商品信息表</title>
  6. <link rel="stylesheet" href="css/style1.css">
  7. </head>
  8. <body>
  9. <table>
  10. <!-- 标题-->
  11. <caption>商品信息表</caption>
  12. <!-- 表头-->
  13. <thead>
  14. <tr>
  15. <th>***</th>
  16. <th>名称</th>
  17. <th>规格</th>
  18. <th>单位</th>
  19. <th>零售价</th>
  20. </tr>
  21. </thead>
  22. <!-- 主体-->
  23. <tbody>
  24. <tr>
  25. <td rowspan="3"></td>
  26. <td>小麦粉</td>
  27. <td>10kg</td>
  28. <td></td>
  29. <td>52.8</td>
  30. </tr>
  31. <tr>
  32. <td>雪花粉</td>
  33. <td>10kg</td>
  34. <td></td>
  35. <td>68</td>
  36. </tr>
  37. <tr>
  38. <td>荞面</td>
  39. <td>散装</td>
  40. <td>500克</td>
  41. <td>3.8</td>
  42. </tr>
  43. <tr>
  44. <td rowspan="3"></td>
  45. <td>皇家贡米</td>
  46. <td>10kg</td>
  47. <td></td>
  48. <td>98</td>
  49. </tr>
  50. <tr>
  51. <td>东北大米</td>
  52. <td>10kg</td>
  53. <td></td>
  54. <td>72.8</td>
  55. </tr>
  56. <tr>
  57. <td>小米</td>
  58. <td>散装</td>
  59. <td>500克</td>
  60. <td>7.8</td>
  61. </tr>
  62. </tbody>
  63. <tfoot>
  64. <tr>
  65. <td colspan="5">大润发超市</td>
  66. </tr>
  67. </tfoot>
  68. </table>
  69. </body>
  70. </html>

CSS部分

  1. table {
  2. /*直角矩形固定box尺寸*/
  3. /*圆角矩形用border-collapse:separate*/
  4. border-collapse: collapse;
  5. /*border: 1px solid gray;*/
  6. width: 700px;
  7. box-shadow: 1px 1px 1px gray;
  8. margin:20px auto;
  9. }
  10. table caption {
  11. font-size: 1.3rem;
  12. margin-bottom: 15px;
  13. }
  14. td,th {
  15. border: 1px solid gray;
  16. padding: 10px;
  17. }
  18. td {
  19. /*表格内容居中显示*/
  20. text-align: center;
  21. }
  22. /*颜色*/
  23. /*隔行变色*/
  24. table tbody tr:nth-of-type(2n+1){
  25. background-color: lightgray;
  26. }
  27. /*表头颜色*/
  28. table thead tr:first-of-type {
  29. background: linear-gradient(green,white);
  30. }
  31. tbody tr:first-of-type > td:first-of-type {
  32. background: linear-gradient(to top, green,white);
  33. }
  34. tbody tr:nth-last-of-type(3) > td:first-of-type {
  35. background: linear-gradient(to right, green, white);
  36. }

使用<div><span><p><ul>…等标签来制作一张课程表

HTML部分

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. <link rel="stylesheet" href="css/style2.css">
  7. </head>
  8. <body>
  9. <article class="table">
  10. <h2 class="caption">课程表</h2>
  11. <div class="thead">
  12. <ul>
  13. <li>时间</li>
  14. <li>星期一</li>
  15. <li>星期二</li>
  16. <li>星期三</li>
  17. <li>星期四</li>
  18. <li>星期五</li>
  19. </ul>
  20. </div>
  21. <div class="tbody">
  22. <ul>
  23. <li>8:00</li>
  24. <li>语文</li>
  25. <li>语文</li>
  26. <li>语文</li>
  27. <li>语文</li>
  28. <li>语文</li>
  29. </ul>
  30. <ul>
  31. <li>9:00</li>
  32. <li>数学</li>
  33. <li>数学</li>
  34. <li>数学</li>
  35. <li>数学</li>
  36. <li>数学</li>
  37. </ul>
  38. <ul>
  39. <li>10:00</li>
  40. <li>英语</li>
  41. <li>英语</li>
  42. <li>英语</li>
  43. <li>英语</li>
  44. <li>英语</li>
  45. </ul>
  46. <ul>
  47. <li>14:00</li>
  48. <li>历史</li>
  49. <li>历史</li>
  50. <li>历史</li>
  51. <li>历史</li>
  52. <li>历史</li>
  53. </ul>
  54. <ul>
  55. <li>15:00</li>
  56. <li>地理</li>
  57. <li>地理</li>
  58. <li>地理</li>
  59. <li>地理</li>
  60. <li>地理</li>
  61. </ul>
  62. <ul>
  63. <li>16:00</li>
  64. <li>美术</li>
  65. <li>美术</li>
  66. <li>美术</li>
  67. <li>美术</li>
  68. <li>美术</li>
  69. </ul>
  70. </div>
  71. </article>
  72. </body>
  73. </html>

CSS部分

  1. .table {
  2. box-sizing: border-box;
  3. display: table;
  4. width: 900px;
  5. border: gray 1px solid;
  6. border-collapse: collapse;
  7. }
  8. .caption {
  9. display: table-caption;
  10. text-align: center;
  11. }
  12. .thead {
  13. display: table-header-group;
  14. font-weight: bold;
  15. font-size: 1.2rem;
  16. text-align: center;
  17. letter-spacing: 5px;
  18. background: linear-gradient(green, white);
  19. color: white;
  20. text-shadow: 1px 1px 0 black;
  21. }
  22. .tbody {
  23. display: table-row-group;
  24. text-align: center;
  25. }
  26. .tfoot {
  27. display: table-footer-group;
  28. width: 100%;
  29. }
  30. div ul {
  31. display: table-row;
  32. }
  33. div ul li {
  34. display: table-cell;
  35. border: 1px solid gray;
  36. padding: 10px;
  37. }

使用绝对定位,实现用户登录框在页面中始终居中显示

HTML部分

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>用户登录页面居中</title>
  6. <link rel="stylesheet" href="css/style3.css">
  7. </head>
  8. <body>
  9. <h3>用户登录</h3>
  10. <div>
  11. <form action="">
  12. <p>
  13. <label for="username">用户名:</label>
  14. <input type="text" id="username" name="username">
  15. </p>
  16. <p>
  17. <label for="password">密码:</label>
  18. <input type="password" id="password" name="password" placeholder="8位数字密码">
  19. </p>
  20. <p>
  21. <input type="button" id="login" name="login" value="登录">
  22. </p>
  23. </form>
  24. </div>
  25. </body>
  26. </html>

CSS部分

  1. h3 {
  2. text-align: center;
  3. }
  4. body {
  5. position: relative;
  6. }
  7. div {
  8. border: 1px solid red;
  9. width: 300px;
  10. position: absolute;
  11. left: 50%;
  12. margin-left: -150px;
  13. }
  14. form > p:last-of-type{
  15. text-align: center;
  16. }

模仿课堂案例, 实现圣杯布局,并写出完整流程与布局思路

1.给页面分区,分别为头部、底部、主体,其中主体分为左侧、右侧和主体内容区
2.css中定义头部、底部的基本属性
3.定义主体的基本属性
4.定义主体内容区的属性,高度、颜色、宽度(因为宽度随页面变化,设置为100%)
5.定义左侧、右侧的公共属性
6.设置主体内的三个元素为浮动元素
7.分别设置左侧、右侧的属性,把定位方式设置为相对定位,使侧部块位置处于主体的左上方和右上方

HTML部分

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>圣杯布局</title>
  6. <link rel="stylesheet" href="css/style4.css">
  7. </head>
  8. <body>
  9. <header>头部</header>
  10. <main>
  11. <article>主题内容区</article>
  12. <aside>左侧</aside>
  13. <aside>右侧</aside>
  14. </main>
  15. <footer>底部</footer>
  16. </body>
  17. </html>

CSS部分

  1. header,footer {
  2. height: 50px;
  3. background-color: lightgray;
  4. }
  5. main {
  6. border: 2px solid red;
  7. box-sizing: border-box;
  8. padding-left: 200px;
  9. padding-right: 200px;
  10. /*转BFC块*/
  11. overflow: auto;
  12. }
  13. main > article {
  14. box-sizing: border-box;
  15. min-height: 600px;
  16. background-color: lightgreen;
  17. width: 100%;
  18. }
  19. aside {
  20. box-sizing: border-box;
  21. min-height: 600px;
  22. width: 200px;
  23. }
  24. main > article,
  25. main > aside:first-of-type,
  26. main > aside:last-of-type {
  27. float: left;
  28. }
  29. main > aside:first-of-type {
  30. background-color: lightcoral;
  31. margin-left: -100%;
  32. /*相对定位*/
  33. position: relative;
  34. left: -200px;
  35. }
  36. main > aside:last-of-type {
  37. background-color: lightblue;
  38. margin-left: -200px;
  39. /*相对定位*/
  40. position: relative;
  41. left: 200px;
  42. }

(选做): 不使用<table>…写表格时,如何实现行与列合并

(选做): 将圣杯布局中的左右二列,使用绝对定位来实现

(选做): 与圣杯类似的”双飞翼”布局如何实现,并实例演示

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post