现在的位置: 首页 > 综合 > 正文

div+css布局

2013年10月13日 ⁄ 综合 ⁄ 共 3902字 ⁄ 字号 评论关闭

1.全部的代码均在一个DIV容器(我暂时这样称呼) Head里面,我们来看看Head的写法

  1. #Head{
  2.     text-align:center;
  3. }
  4. 为什么Head前面有一个"#"号呢?
  5. 而有的却是在前面加一个""比如 "Head",有时候写css的时候干脆什么也不加,比如 td,body,他们有什么区别,具体怎么用,如果仔细你就会发现在HTML代码的DIV容器里面,有的是 <div id="Head"></div> 而有的是这样 <div class="HackBox"></div>
  6. idclass字面上的意思,我们也已经了解了,id具有唯一性,class是一个类,适用于可多次重复使用的容器,而前面什么也不带的,便是 CSS里默认的通用于HTML代码的描叙,即对HTML里的代码起全局作用,比如 td,便是对HTML表格里面的全部列起作用,text-align:center是指在此容器里面的文字全部居中对齐,我们注意到,行后面还有一个分号 ";",
  7. 语法 text-align : left | right | center | justify
  8. 取值说明:
  9. left   : 默认值。左对齐
  10. right   : 右对齐
  11. center   : 居中对齐
  12. justify   : 两端对齐
  13.  
  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.  
  24. position : static | absolute | fixed | relative
  25. 取值:
  26. static   : 默认值。无特殊定位,对象遵循HTML定位规则
  27. absolute   : 将对象从文档流中拖出,使用 left right top bottom 等属性相对于其最接近的一个最有定位设置的父对象进行绝对定位。如果不存在这样的父对象,则依据 body 对象。而其层叠通过 z-index 属性定义
  28. fixed   :未支持。对象定位遵从绝对(absolute)方式。但是要遵守一些规范
  29. relative   :对象不可层叠,但将依据 left right top bottom 等属性在正常文档流中偏移位置
  30.  
  31. width : auto | length
  32. auto   : 默认值。无特殊定位,根据HTML定位规则分配
  33. length   : 由浮点数字和单位标识符组成的长度值 | 百分数。百分数是基于父对象的宽度。不可为负数。 可以用相对长度象素单位px或者绝对长度in等做单位(1in = 2.54cm = 25.4 mm = 72pt = 6pc)
  34.  
  35. margin:10px auto 10px;
  36. 检索或设置对象四边的外补丁
  37. 如果提供全部四个参数值,将按上-右-下-左(顺时针方向)的顺序作用于四边。如果只提供一个,将用于全部的四边。如果提供两个,第一个用于上-下,第二个用于左-右。如果提供三个,第一个用于上,第二个用于左-右,第三个用于下。
  38.  
  39. text-align:left;
  40. 我们看到Head里面已经有设置文字对齐是居中的了,而这里又定义文字居左,那么到底文字怎么对齐呢?如果有相冲突的定义,CSS将按最近的一个定义来执 行,这跟HTML中的是一样的,比如<font color=red><font color=green>我到底是什么颜色?</font></font>
  41.  
  42. 3.
  43. #Head #Logo{
  44.     width: 240px;
  45.     height: 31px;
  46.     float: left;
  47.     margin-left: 2px;
  48. }
  49. width(宽度),height(高度)都不说了
  50. float : none | left | right
  51. 取值:
  52. none   : 默认值。对象不飘浮
  53. left   : 文本流向对象的右边
  54. right   : 文本流向对象的左边
  55. 翻译为漂浮,left说明是从左开始排列
  56. margin-left: 2px; 相当于 maign:0px;0px;0px;2px
  57. 这里Logo容器说明的是,从左开始排列,宽度为240px,高度为31px,左补丁(左边空余)2px
  58.  
  59. 4.HeadNavBar左边导航条
  60. #Head #HeadNavBar{
  61.     float:right;
  62.     clear:right;
  63.     background: url(images/header_mm_bk.gif) left top no-repeat;
  64.     width:510px;
  65. }
  66.  
  67. clear:right;清除右浮动,说明右边不能再有容器
  68. clear : none | left | right | both
  69. background: url(images/header_mm_bk.gif) left top no-repeat;
  70. (意思是背景图片左,上对齐,不重复)
  71. background : background-color || background-image || background-repeat || background-attachment || background-position
  72. background-color:silver; 背景色
  73. background-image:url(http://www.dayanmei.com/images/space.gif);
  74. 当同时存在背景图片和背景色时背景色将被覆盖
  75. background-repeat : repeat | no-repeat | repeat-x | repeat-y
  76. 取值:
  77. repeat   : 默认值。背景图像在纵向和横向上平铺
  78. no-repeat   : 背景图像不平铺
  79. repeat-x   : 背景图像仅在横向上平铺
  80. repeat-y   : 背景图像仅在纵向上平铺
  81. background-attachment : scroll | fixed
  82. 取值:
  83. scroll   : 默认值。背景图像是随对象内容滚动
  84. fixed   : 背景图像固定
  85. background-position : length || length
  86. background-position : position || position
  87. 取值:
  88. length   : 百分数 | 由浮点数字和单位标识符组成的长度值。  
  89. position   : top | center | bottom | left | center | right
  90.  
  91. 整句的意思是宽度为510px象素的容器从右往左排列
  92.  
  93. 5.
  94. #Head ul{
  95.     list-style-type:none;
  96.     margin:0;
  97.     padding:0;
  98. }
  99. list-style-type:none;
  100. list-style : list-style-image || list-style-position || list-style-type
  101. list-style-image : url ( url );可以将列表样式改变为图片
  102.  
  103. list-style-type : disc | circle | square | decimal | lower-roman | upper-roman | lower-alpha | upper-alpha | none
  104. 取值:可以将列表改变为其他样式
  105. disc   : CSS1   默认值。实心圆
  106. circle   : CSS1   空心圆
  107. square   : CSS1   实心方块
  108. decimal   : CSS1   阿拉伯数字
  109. lower-roman   : CSS1   小写罗马数字
  110. upper-roman   : CSS1   大写罗马数字
  111. lower-alpha   : CSS1   小写英文字母
  112. upper-alpha   : CSS1   大写英文字母
  113. none   : CSS1   不使用项目符号
  114.  
  115.  
  116. 6.
  117. #Head #HeadNavBar li{
  118.     float:left;
  119.     height:31px;
  120.     background: url(images/header_mm_sep.gif) left center no-repeat;
  121.     display:inline;
  122. }
  123. display:inline; 内联对象的默认值。将对象强制作为内联对象呈递,从对象中删除行(显示在行内,超出的将不显示)
  124. display : block | none | inline | inline-block
  125.  
  126. 7.
  127. #Head #HeadNavBar li.NoSep{
  128.     background: none;
  129.     margin-left: 5px;
  130. }
  131. 当列表区块内标志类为NoSep,没有背景色"background: url(images/header_mm_sep.gif) left center no-repeat;",并且左补丁为5px
  132.  
  133. 8.#MyTaoBao {
  134.     padding-left: 14px!important;
  135.     margin-left: 9px!important;
  136.     margin-left: 4px;
  137.     background:transparent url(images/header_mm_mytb_icon.gif) no-repeat left center;
  138. }
  139. padding:lenth;内补丁,用法参考margin,
  140. padding-left: 14px;是指左边空余14px的值,这空余是用来放置居左中的背景图片的
  141. !important;提升指定样式规则的应用优先权。
  142.  
  143. 9.设置列表内的链接样式
  144. #Head #HeadNavBar li a{
  145.     display:block;
  146.     padding: 0 6px 0 7px;
  147.     float:left;

抱歉!评论已关闭.