博客列表 >CSS框模型

CSS框模型

王娇
王娇原创
2020年04月18日 15:54:53608浏览

演示地址

http://xuanransoftware.com/phpStudy/0408/

效果图

学习总结

  • 1.知道了盒模型的基本概念
  • 2.使用flex布局时,如果使用了元素的内边距padding后,把元素框的重要属性box-sizing:设置为border-box
  • 3.如果想要元素框在父元素框中居中显示则定义属性margin-left: auto margin-right: auto
  • 4.默认情况下元素框中的元素框是块元素,如果想行内显示,则需要定义属性display: flex

html示例代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <link rel="stylesheet" href="css/style.css" type="text/css" />
  7. <title>同城信息网</title>
  8. <style>
  9. @media screen and (max-width: 400px) {
  10. nav {
  11. display: none;
  12. }
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <header>
  18. <!-- 页面导航 -->
  19. <nav>
  20. <img src="images/logo.jpg" width="100" height="50" />
  21. <ul>
  22. <li>
  23. <a href="mainIndex.html" target="mainFrame">首页</a>
  24. <a href="formTable.html" target="mainFrame">用户注册</a>
  25. <a href="table.html" target="mainFrame">表格</a>
  26. <a href="listTable.html" target="mainFrame">列表</a>
  27. </li>
  28. </ul>
  29. </nav>
  30. </header>
  31. <main>
  32. <aside>
  33. <section>
  34. <label for="" class="iconfont"> 新闻资讯</label>
  35. </section>
  36. <section>
  37. <label for="" class="iconfont"> 搜索内容</label>
  38. </section>
  39. <section>
  40. <label for="" class="iconfont"> 联系我们</label>
  41. <ul>
  42. <li>名称:北京瑄然软件</li>
  43. <li>地址:北京顺义区...</li>
  44. <li>电话:<a href="tel:15010046927">1501004xxxx</a></li>
  45. <li>
  46. 邮箱:<a href="mailto:573661083@qq.com">5736610xx@qq.com</a>
  47. </li>
  48. </ul>
  49. </section>
  50. </aside>
  51. <section class="mainclass">
  52. <iframe
  53. name="mainFrame"
  54. width="695"
  55. height="495"
  56. scrolling="auto"
  57. style="border: 0px;"
  58. src="mainIndex.html"
  59. >
  60. </iframe>
  61. </section>
  62. </main>
  63. <footer>
  64. <section>
  65. <a href="http://www.xuanransoftware.com/" target="_blank"
  66. >北京瑄然软件工作室</a
  67. >
  68. <a href="https://www.php.cn/" target="_blank">友情链接:php中文网</a>
  69. </section>
  70. </footer>
  71. </body>
  72. </html>

css示例代码

  1. * {
  2. margin: 0px;
  3. padding: 0px;
  4. font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  5. }
  6. @font-face {
  7. font-family: "iconfont";
  8. src: url("../fontIcon/iconfont.eot");
  9. src: url("../fontIcon/iconfont.eot?#iefix") format("embedded-opentype"),
  10. url("../fontIcon/iconfont.woff2") format("woff2"),
  11. url("../fontIcon/iconfont.woff") format("woff"),
  12. url("../fontIcon/iconfont.ttf") format("truetype"),
  13. url("../fontIcon/iconfont.svg#iconfont") format("svg");
  14. }
  15. .iconfont {
  16. font-family: "iconfont" !important;
  17. font-size: 16px;
  18. font-style: normal;
  19. -webkit-font-smoothing: antialiased;
  20. -moz-osx-font-smoothing: grayscale;
  21. }
  22. header {
  23. width: 920px;
  24. height: 65px;
  25. background-color: lightseagreen;
  26. margin-left: auto;
  27. margin-right: auto;
  28. box-sizing: border-box;
  29. }
  30. main {
  31. width: 920px;
  32. margin-left: auto;
  33. margin-right: auto;
  34. box-sizing: border-box;
  35. display: flex;
  36. }
  37. footer {
  38. width: 920px;
  39. height: 50px;
  40. background-color: lightseagreen;
  41. margin-left: auto;
  42. margin-right: auto;
  43. display: flex;
  44. box-sizing: border-box;
  45. }
  46. footer > section {
  47. height: 30px;
  48. margin-top: 10px;
  49. margin-left: auto;
  50. margin-right: auto;
  51. }
  52. nav {
  53. font-size: large;
  54. font-weight: bold;
  55. display: flex;
  56. height: 65px;
  57. box-sizing: border-box;
  58. background-color: white;
  59. }
  60. nav img {
  61. margin-top: 5px;
  62. margin-left: 5px;
  63. }
  64. nav ul {
  65. margin-top: 20px;
  66. margin-left: 40px;
  67. margin-right: auto;
  68. display: flex;
  69. list-style: none;
  70. }
  71. nav ul a {
  72. text-decoration: none;
  73. padding: 0 15px;
  74. }
  75. nav ul a:link {
  76. color: blue;
  77. }
  78. nav ul a:visited {
  79. color: blueviolet;
  80. }
  81. nav ul a:hover {
  82. color: tomato;
  83. }
  84. aside {
  85. width: 220px;
  86. height: 500px;
  87. box-sizing: border-box;
  88. }
  89. aside > section:nth-of-type(-n + 2) {
  90. height: 170px;
  91. margin-top: 2px;
  92. border: 1px solid lightgreen;
  93. }
  94. aside > section:last-of-type {
  95. margin-top: 2px;
  96. border: 1px solid lightgreen;
  97. }
  98. aside > section > ul > li {
  99. list-style-type: none;
  100. margin-top: 5px;
  101. padding: 2px;
  102. }
  103. .mainclass {
  104. display: flex;
  105. margin-left: 0px;
  106. height: 500px;
  107. width: 695px;
  108. box-sizing: border-box;
  109. }
  110. button {
  111. height: 30px;
  112. width: 100;
  113. border: none;
  114. outline: none;
  115. background-color: lightseagreen;
  116. color: white;
  117. }
  118. button:hover {
  119. background-color: lightsalmon;
  120. cursor: pointer;
  121. }
  122. form {
  123. padding: 30px;
  124. box-shadow: 0 0 8px #888;
  125. border-radius: 10px;
  126. margin: auto;
  127. background-color: lightskyblue;
  128. display: grid;
  129. gap: 15px;
  130. }
  131. form fieldset {
  132. align-items: center;
  133. }
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议