转:div+css布局实例分析(一)

  1. 1.全部的代码均在一个DIV容器(我暂时这样称呼) Head里面,我们来看看Head的写法
  2. #Head{
  3.     text-align:center;
  4. }
  5. 为什么Head前面有一个"#"号呢?
  6. 而有的却是在前面加一个"."比如 ".Head",有时候写css的时候干脆什么也不加,比如 td,body,他们有什么区别,具体怎么用,如果仔细你就会发现在HTML代码的DIV容器里面,有的是 <div id="Head"></div> 而有的是这样 <div class="HackBox"></div>
  7. 从id和class字面上的意思,我们也已经了解了,id具有唯一性,而class是一个类,适用于可多次重复使用的容器,而前面什么也不带的,便是 CSS里默认的通用于HTML代码的描叙,即对HTML里的代码起全局作用,比如 td,便是对HTML表格里面的全部列起作用,text-align:center是指在此容器里面的文字全部居中对齐,我们注意到,行后面还有一个分号 ";",
  8. 语法 text-align : left | right | center | justify 
  9. 取值说明:
  10. left  : 默认值。左对齐 
  11. right  : 右对齐 
  12. center  : 居中对齐 
  13. justify  : 两端对齐 
  14. 2.HeadTop
  15. #Head #HeadTop{
  16.     position:relative;
  17.     width:760px;
  18.     margin:10px auto 10px;
  19.     text-align:left;
  20. }
  21. 为什么#HeadTop前面会有一个#Head?
  22. 我们发现#headTop是嵌套在#Head里面的,为了Head里面的设置在HeadTop里面同样生效,将HeadTop放在了Head后面
  23. position : static | absolute | fixed | relative 
  24. 取值:
  25. static  : 默认值。无特殊定位,对象遵循HTML定位规则 
  26. absolute  : 将对象从文档流中拖出,使用 left , right , top , bottom 等属性相对于其最接近的一个最有定位设置的父对象进行绝对定位。如果不存在这样的父对象,则依据 body 对象。而其层叠通过 z-index 属性定义 
  27. fixed  :未支持。对象定位遵从绝对(absolute)方式。但是要遵守一些规范 
  28. relative  :对象不可层叠,但将依据 left , right , top , bottom 等属性在正常文档流中偏移位置 
  29. width : auto | length
  30. auto  : 默认值。无特殊定位,根据HTML定位规则分配 
  31. length  : 由浮点数字和单位标识符组成的长度值 | 百分数。百分数是基于父对象的宽度。不可为负数。 可以用相对长度象素单位px或者绝对长度in等做单位(1in = 2.54cm = 25.4 mm = 72pt = 6pc)
  32. margin:10px auto 10px;
  33. 检索或设置对象四边的外补丁
  34. 如果提供全部四个参数值,将按上-右-下-左(顺时针方向)的顺序作用于四边。如果只提供一个,将用于全部的四边。如果提供两个,第一个用于上-下,第二个用于左-右。如果提供三个,第一个用于上,第二个用于左-右,第三个用于下。
  35. text-align:left;
  36. 我们看到Head里面已经有设置文字对齐是居中的了,而这里又定义文字居左,那么到底文字怎么对齐呢?如果有相冲突的定义,CSS将按最近的一个定义来执 行,这跟HTML中的是一样的,比如<font color=red><font color=green>我到底是什么颜色?</font></font>
  37. 3.
  38. #Head #Logo{
  39.     width240px;
  40.     height31px;
  41.     floatleft;
  42.     margin-left2px;
  43. }
  44. width(宽度),height(高度)都不说了
  45. float : none | left | right 
  46. 取值:
  47. none  : 默认值。对象不飘浮 
  48. left  : 文本流向对象的右边 
  49. right  : 文本流向对象的左边
  50. 翻译为漂浮,left说明是从左开始排列
  51. margin-left2px; 相当于 maign:0px;0px;0px;2px
  52. 这里Logo容器说明的是,从左开始排列,宽度为240px,高度为31px,左补丁(左边空余)2px
  53. 4.HeadNavBar左边导航条
  54. #Head #HeadNavBar{
  55.     float:right;
  56.     clear:right;
  57.     backgroundurl(images/header_mm_bk.gif) left top no-repeat;
  58.     width:510px;
  59. }
  60. clear:right;清除右浮动,说明右边不能再有容器
  61. clear : none | left | right | both
  62. backgroundurl(images/header_mm_bk.gif) left top no-repeat;
  63. (意思是背景图片左,上对齐,不重复)
  64. background : background-color || background-image || background-repeat || background-attachment || background-position
  65. background-color:silver; 背景色
  66. background-image:url(http://www.dayanmei.com/images/space.gif); 
  67. 当同时存在背景图片和背景色时背景色将被覆盖
  68. background-repeat : repeat | no-repeat | repeat-x | repeat-y 
  69. 取值:
  70. repeat  : 默认值。背景图像在纵向和横向上平铺 
  71. no-repeat  : 背景图像不平铺 
  72. repeat-x  : 背景图像仅在横向上平铺 
  73. repeat-y  : 背景图像仅在纵向上平铺
  74. background-attachment : scroll | fixed 
  75. 取值:
  76. scroll  : 默认值。背景图像是随对象内容滚动 
  77. fixed  : 背景图像固定 
  78. background-position : length || length 
  79. background-position : position || position 
  80. 取值:
  81. length  : 百分数 | 由浮点数字和单位标识符组成的长度值。  
  82. position  : top | center | bottom | left | center | right 
  83. 整句的意思是宽度为510px象素的容器从右往左排列
  84. 5.
  85. #Head ul{
  86.     list-style-type:none;
  87.     margin:0;
  88.     padding:0;
  89. }
  90. list-style-type:none;
  91. list-style : list-style-image || list-style-position || list-style-type 
  92. list-style-image : url ( url );可以将列表样式改变为图片
  93. list-style-type : disc | circle | square | decimal | lower-roman | upper-roman | lower-alpha | upper-alpha | none 
  94. 取值:可以将列表改变为其他样式
  95. disc  : CSS1  默认值。实心圆 
  96. circle  : CSS1  空心圆 
  97. square  : CSS1  实心方块 
  98. decimal  : CSS1  阿拉伯数字 
  99. lower-roman  : CSS1  小写罗马数字 
  100. upper-roman  : CSS1  大写罗马数字 
  101. lower-alpha  : CSS1  小写英文字母 
  102. upper-alpha  : CSS1  大写英文字母 
  103. none  : CSS1  不使用项目符号 
  104. 6.
  105. #Head #HeadNavBar li{
  106.     float:left;
  107.     height:31px;
  108.     backgroundurl(images/header_mm_sep.gif) left center no-repeat;
  109.     display:inline;
  110. }
  111. display:inline; 内联对象的默认值。将对象强制作为内联对象呈递,从对象中删除行(显示在行内,超出的将不显示)
  112. display : block | none | inline | inline-block 
  113. 7.
  114. #Head #HeadNavBar li.NoSep{
  115.     backgroundnone;
  116.     margin-left5px;
  117. }
  118. 当列表区块内标志类为NoSep时,没有背景色"background: url(images/header_mm_sep.gif) left center no-repeat;",并且左补丁为5px
  119. 8.#MyTaoBao {
  120.     padding-left14px!important;
  121.     margin-left9px!important;
  122.     margin-left4px;
  123.     background:transparent url(images/header_mm_mytb_icon.gif) no-repeat left center;
  124. }
  125. padding:lenth;内补丁,用法参考margin,
  126. padding-left14px;是指左边空余14px的值,这空余是用来放置居左中的背景图片的
  127. !important;提升指定样式规则的应用优先权。
  128. 9.设置列表内的链接样式
  129. #Head #HeadNavBar li a{
  130.     display:block;
  131.     padding0 6px 0 7px;
  132.     float:left;
  133.     height:31px;
  134.     line-height:31px;
  135.     color#0f3a66;
  136.     font-size13px;
  137. }
  138. display:block; 以块状呈现
  139. padding0 6px 0 7px;左右内补丁各为7px,6px
  140. color#0f3a66;链接时文字颜色为#0f3a66;
  141. 链接的完整定义还可以包含背景颜色background,链接样式text-decoration(text-decoration : none[无装饰] || underline[下划线] || blink[文字闪烁] || overline[上划线] || line-through[贯穿线])
  142. 链接的顺序应该是这样的(LVHA)
  143. a:link
  144. a :visited
  145. a :hover
  146. a :active
  147. #Head #HeadNavBar li a:hover{
  148.     color#e60;
  149. }
  150. 10.
  151. #Head #HeadNavBar li#AdvanceBox {
  152.     backgroundnone;
  153.     margin-left10px;
  154. }
  155. 由于AdvanceBox是在块li里面,故顺序为#Head #HeadNavBar li#AdvanceBox,这句意思是无背景,左外补丁(左空余)为10px;
  156. 11.为#AdvanceBox内的其他表单元素定义
  157. #Head #HeadNavBar li#AdvanceBox form {
  158.     margin:0;
  159.     padding:0;
  160.     margin-left:8px;
  161.     margin-top:5px;
  162. }
  163. #Head #HeadNavBar li#AdvanceBox .HeaderSearchBox {
  164.     display:block;
  165.     float:left;
  166.     width:112px;
  167.     height:15px!important;
  168.     height /*ie55*/21px;
  169.     padding:3px 2px 1px 2px
  170.     padding-right:0;
  171.     border1px solid #7ad2ff;
  172.     background:url(images/header_mm_srch_bk.png) no-repeat
  173.     color#000;
  174. }
  175. #Head #HeadNavBar li#AdvanceBox input.DC {
  176.     color#90B1C5 !important;
  177. }
  178. #Head #HeadNavBar li#AdvanceBox .HeaderSearchBtn {
  179.     display:block;
  180.     float:left;
  181.     margin-left /*ie55*/-3px;
  182. }
  183. #Head #HeadNavBar li#AdvanceBox li {
  184.     backgroundnone!important;
  185. }
  186. 12.#QuickLinks
  187. #Head #QuickLinks{
  188.     float:right;
  189.     width:750px;
  190.     margin-top:6px;
  191.     margin-right:6px;
  192. }
  193. 右浮动,宽度为750px,上,右补丁各为6px
  194. 13.为#Head #QuickLinks定义列表li样式
  195. #Head #QuickLinks li{
  196.     floatright;
  197.     margin-left:10px;
  198.     line-height:21px;
  199. }
  200. line-height:21px; 行高21px;
  201. 14.定义#Head #QuickLinks li内链接样式,多个相同的定义时可以用","分割开,而且路径要写完整
  202. #Head #QuickLinks li a:link, #Head #QuickLinks li a:visited {
  203.     font-style:normal;
  204.     font-weight:normal;
  205.     font-size12px;
  206.     color:#04d;
  207. }
  208. #Head #QuickLinks li a:hover, #Head #QuickLinks li a:active {
  209.     color:#e60;
  210. }
  211. 15.
  212. .HackBox{
  213.    border-top:1px solid transparent !important;
  214.    border-top:0;
  215.    clear:both;
  216. }
  217. 这里有两个重复定义的border-top(上边框,!important优先,边框为1px,透明
  218. clear:both; 左右浮动均清除,类似换一行
  219. 淘宝头部导航已经基本分析完成,现在总结一下:
  220. (1).容器div可以嵌套,比如 <div id="Head"><div id="Logo"></div></div>,嵌套时容器的写法:需要在前面加上容器的命名,如 #Head #Logo,我们发现,Logo虽然在容器"HeadTop"里面却不用写成 #Head #HeadTo#Logo,因为HeadTop并没有对Logo限制
  221. (2).独特的容器名字前面加符号 "#",通用的前面加符号小句点"."
  222. (3).容器的基本参数包括 外补丁 margin,内补丁 padding,宽度 width,背景 background,浮动 float,清除 clear,这几个参见参数的用法要熟记
  223. (4).需要换行显示时用 clear:both;
  224. (5).可以单独为某个容器定义链接样式, 顺序为 LVHA(a:link,a:visited,a:hover,a:active),链接样式的几个参数背景(background),内补丁 (padding)宽度(width)描述(text-decoration)文字颜色(color)等,可以设置链接以块状方式显示
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值