一 CSS(Cascading Style Sheets)级联样式表,作用:装饰HTML
二 CSS语法由三部分构成:选择器,属性,值。
三 HTML引用CSS的三种方法(以下为示例代码) :分别为行内样式,内嵌式,和链接式.如下:p元素为行内样式,div元素为嵌入式(写在head元素内),
另外一个为链接式:使页面框架html和css样式完全分离为两个或多个文件,是的前期制作和后期维护都很方便.
其中的test.css和test2.css都是链接式,是的html和css完全分开.
HTML CODE
- <!DOCTYP>
- <HTML>
- <HEAD>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <style type="text/css">
- div{
- background-color:#FF0000;
- }
- @import "test2.css";
- </style>
- <link rel="stylesheet" type="text/css" href="test.css"></link>
- </HEAD>
- <BODY>
- <P style="background-color:yellow">这个是行内样式表</p><br><hr>
- <div >这个是内部样式表</div><br><hr>
- <span>这个是使用了test.css中的外部样式</span><br><hr>
- <a href="#">这个是使用import(test2.css的样式)外部样式</a>
- </BODY>
- </HTML>
CSS CODE
test.css
- span{
- background-color:#FF0000;
- }
test2.css
- a{
- background-color:#FF0000;
- }
网上转载:DIV+CSS 常用属性
字体属性:
1.font-size:12px; 字体大小
2.font-weight:bold; 字体加粗
3.font-family:"宋体"; 字体的种类
背景属性:
1.background-color:#000; 背景颜色 简写:background:#00;
2.background-image:url("图片路径"); 设置背景图片
简写:background:url("图片路径");
3.background-repeat:repeat-x/repeat-y/no-repeat; 图象平铺
注:可以简写background:背景颜色/背景图片/背景平铺
文本属性:
1.letter-spacing:12px/normal;字间隔 normal 无
2.line-height:25px; 行高
3.text-indent:24px; 文本缩进
方框属性:
1.border:1px solid #000; 边框
2.border-top/left/right/bottom:1px solid/dashed #000; 设置上左右下边框
solid :实线 dashed:虑线
3.display:block; 转块元素
displya:inline;转行内元素
定位:
position:absolute; 绝对定位
position:relative; 相对定位
margin:0 auto;居中
margin 边距
margin-top:0px; margin-left:0px; margin-bottom:0px; margin-right:0px;
padding 内边距
padding-left:10px; padding-right:10px; padding-top:10px; padding-bottom:10px;
list-style:none;
float:left/right;css浮动
cursor:pointe;鼠标为手型
clear:both;清除浮动
css简写
font
简写:
font:italic small-caps bold 12px/1.5em arial,verdana;等效于:
font-style:italic;
font-variant:small-caps;
font-weight:bold;
font-size:12px;
line-height:1.5em;
font-family:arial,verdana;顺序:font-style | font-variant | font-weight | font-size | line-height | font-family
(注:简写时,font-size和line-height只能通过斜杠/组成一个值,不能分开写。)
background
简写:background:#fff url(bg.gif) no-repeat fixed left top;等效于:
background-color:#fff;
background-image:url(bg.gif);
background-repeat:no-repeat;
background-attachment:fixed;
background-position:left top;顺序:background-color | background-image | background-repeat | background-attachment | background-position
简写:
margin:1px 0 2em -20px;等效于:
margin-top:1px;
margin-right:0;
margin-bottom:2em;
margin-left:-20px;顺序:margin-top | margin-right | margin-bottom | margin-left
padding的简写和margin完全一样。
链接式
CSS
样式表是使用频率最高,也是最为实用的方法。它
将
HTML
页面本身与
CSS
样式风格分离为两个或者多个文件,
实现了页面框架
HTML
代码与美工
CSS
代码的完全分离,使得
前期制作和后期维护都十分方便,
网站后台的技术人员与美工设
计都也可以很好的分工合作。而且对于同一个
CSS
文件可以链
接到多个
HTML
文件中,甚至可以链接到整个网站的所有页面
中,
使得网站整体风格统一协调,
并且后期维护的工作量也大大
减少。