网页制作之HTML+CSS布局

忘是亡心i 2022-04-15 01:05 355阅读 0赞

CSS网页布局:

可以分为三种:1.固定布局

2.流动布局 (是百分百布局)

3.弹性布局(可用于移动APP开发)

元素基本样式:

1.行内样式:直接写在部分的标签里面

  1. <body>
  2. <span><a href="#" style="color: red">每满千减百</a></span>
  3. </body>
  4. </html>

2.内嵌样式 :写在部分,用标签包起来

  1. <!DOCTYPE html>
  2. <html>
  3. <head lang="en">
  4. <meta charset="UTF-8">
  5. <title>淘宝</title>
  6. <style>
  7. *{
  8. margin: 0;
  9. padding: 0;
  10. }
  11. .block{
  12. position: absolute;
  13. top: 0px;
  14. bottom: 0px;
  15. left: 0px;
  16. right: 0px;
  17. margin: auto;
  18. width: 1000px;
  19. height: 500px;
  20. border: 1px solid #355162;
  21. }
  22. </style>

3.外部样式:是在CSS写入样式,在html的部分用标签链接,注意地址一定要写正确,否则链接无效。

  1. <!DOCTYPE html>
  2. <html>
  3. <head lang="en">
  4. <meta charset="UTF-8">
  5. <title>京东</title>
  6. <link rel="stylesheet" href="index.css">
  7. <link rel="stylesheet" href="./css/iconfont.css">
  8. </head>

元素的样式可以混合使用

图片标签

图像标签是自闭和标签,写法

图像标签的实现路径有三种:1.相对路径 2.绝对路径 3.远程路径

定位

定位分为三种:1.相对定位(占位置)

  1. 2.绝对定位(不占位置)
  2. 3.固定定位

相对定位和绝对定位使用较多,并且两者可以混合使用,一般是将绝对定位套进相对定位中使用,即给父元素使用相对定位,给子元素使用绝对定位。

搜索框

直接用标签表示

悬停伪类

用属性:hover表示,当鼠标放置需要悬停的文字或图片上时,会显示出所设置的属性样式,如字体颜色,子集,背景色等等

这里我们以固定布局,外部样式为例,以京东部分网页为模板来展示

20181121113542953.png

html部分展示如下

  1. <div class="two">
  2. <div class="img"><img src="./img/5b5edd7eNc217df1c.gif"></div>
  3. <div class="two_center">
  4. <div class="two_center1">
  5. <input type="text"/>
  6. <span class="two_center11"><i class="iconfont">&#xf0151</i></span>
  7. <span class="two_center12"><i class="iconfont">&#xf012c</i></span>
  8. </div>
  9. <div class="two_center2">
  10. <span><a href="#" style="color: red">每满千减百</a></span>
  11. <span><a href="#">坚果零食</a></span>
  12. <span><a href="#">0元试用</a></span>
  13. <span><a href="#">1元秒杀</a></span>
  14. <span><a href="#">每100-40</a></span>
  15. <span><a href="#">一加6T</a></span>
  16. <span><a href="#">空调好物</a></span>
  17. <span><a href="#">家装建材</a></span>
  18. <span><a href="#">组装电脑</a></span>
  19. </div>
  20. <div class="two_right">
  21. <i class="iconfont">&#xf0179</i>
  22. 我的购物车
  23. <span class="shuzi">0</span>
  24. </div>
  25. </div>
  26. <div class="two_center3">
  27. <span><a href="#">秒杀</a></span>
  28. <span><a href="#">优惠券</a></span>
  29. <span><a href="#">PLUS会员</a></span>
  30. <span><a href="#">闪购</a></span>
  31. <span class="shuxian"></span>
  32. <span><a href="#">拍卖</a></span>
  33. <span><a href="#">京东时尚</a></span>
  34. <span><a href="#">京东超市</a></span>
  35. <span><a href="#">京东生鲜</a></span>
  36. <span class="shuxian"></span>
  37. <span><a href="#">全球购</a></span>
  38. <span><a href="#">京东金融</a></span>
  39. </div>
  40. </div>

CSS部分

  1. .two{
  2. position: relative;
  3. width: 1190px;
  4. height: 140px;
  5. margin: 0 auto;
  6. }
  7. .img{
  8. position: absolute;
  9. margin-top: -60px;
  10. width: 190px;
  11. height: 170px;
  12. background-color: white;
  13. background-size: 190px 170px;
  14. box-shadow: 0px -5px 15px silver;
  15. border-bottom: 1px solid silver;
  16. }
  17. .two_center{
  18. position: relative;
  19. margin-left: 320px;
  20. margin-top: 30px;
  21. width: 550px;
  22. height: 60px;
  23. }
  24. .two_center1{
  25. position: absolute;
  26. width: 550px;
  27. height: 35px;
  28. background-color: white;
  29. }
  30. .two_center1>input{
  31. width: 450px;
  32. height: 35px;
  33. outline: none;
  34. border-style: none;
  35. padding-left: 5px;
  36. }
  37. .two_center11{
  38. position: absolute;
  39. width: 40px;
  40. height: 35px;
  41. right: 60px;
  42. text-align: center;
  43. line-height: 35px;
  44. }
  45. .two_center11>i{
  46. font-size: 25px;
  47. color: #696969;
  48. }
  49. .two_center11>i:hover{
  50. color: red;
  51. }
  52. .two_center12{
  53. position: absolute;
  54. right: 0;
  55. width: 60px;
  56. height: 35px;
  57. text-align: center;
  58. line-height: 35px;
  59. background-color: #ff0000;
  60. }
  61. .two_center12>i{
  62. font-size: 25px;
  63. color: white;
  64. }
  65. .two_center2{
  66. display: inline-block;
  67. margin-top: 35px ;
  68. width: 550px;
  69. height: 25px;
  70. }
  71. .two_center2>span{
  72. margin-right: 6px;
  73. line-height: 25px;
  74. text-align: center;
  75. font-size: 12px;
  76. }
  77. .two_center2>span>a{
  78. text-decoration: none;
  79. color: #ababab;
  80. }
  81. .two_center2>span>a:hover{
  82. color: red;
  83. }
  84. .two_center3{
  85. margin-top: 30px;
  86. margin-left: 230px;
  87. }
  88. .two_center3>span {
  89. padding-right: 20px;
  90. font-size: 14px;
  91. }
  92. .two_center3>span a{
  93. text-decoration: none;
  94. color: black;
  95. }
  96. .two_center3>span a:hover{
  97. color: red;
  98. }
  99. .shuxian{
  100. display: inline-block;
  101. height: 10px;
  102. width: 1px;
  103. border-left: 1px solid #9b9b9b;
  104. }
  105. .two_right{
  106. position: absolute;
  107. margin-left: 580px;
  108. top: 0px;
  109. left: 0px;
  110. z-index: 10;
  111. width: 188px;
  112. height: 33px;
  113. border: 1px solid silver;
  114. background-color: white;
  115. text-align: center;
  116. line-height: 33px;
  117. font-size: 13px;
  118. color: #ff426f;
  119. }
  120. .two_right>i{
  121. font-size: 18px;
  122. margin-left: 5px;
  123. }
  124. .shuzi{
  125. position: relative;
  126. display: inline-block;
  127. top: -8px;
  128. width: 12px;
  129. height: 15px;
  130. border-radius: 50%;
  131. color: white;
  132. background-color: red;
  133. line-height: 15px;
  134. text-align: center;
  135. }

需要注意的是,在保存文件的时候要注意路径是否一致,否则图片加载不出来,或者会出现样式混乱的情况。

发表评论

表情:
评论列表 (有 0 条评论,355人围观)

还没有评论,来说两句吧...

相关阅读

    相关 网页布局基础

    1  CSS 规定的定位机制有三种,分别是         标准文档流(Normal folw)         浮动(Floats)         绝对定位(Abso

    相关 网页布局

    布局方式 > 静态布局:网页上所有元素尺寸使用px为单位。 > 流式布局:屏幕分辨率变化时,页面里元素的大小会变化而但布局不变。 > 自适应布局:自适应布局的特点

    相关 网页制作pdf

    前言 沉迷农药,抖音,总归是不好的。在要吃苦的年纪里选择安逸,那么老了一定会后悔,埋怨年轻的时候不知道努力的自己。于是又找出了尘封已久的kindle,打算好好看看书,给自

    相关 网页布局方式

    总结一下下网页布局的几种方式: 1. 流式布局:为网页设置一个相对的宽度,通常以百分比%做为长度单位。更加适合屏幕变化。 2. 栅格化布局:将网页宽度人为的划分成均等的长