css cascading style sheets层叠样式表
它能对网页的字体,背景,颜色和特殊效果以精确的控制,便于轻松的布局页面。css分为 类、标签,高级(也叫伪类)三种类型,css代码可以内嵌于一个html页面内,也可以独立成一个css文件,然后被html页面所引用
类 是可以应用于任何标签,是一种自定义的css类型,类的名字是以点开始的。
标签 是重新定义特定标签的外观,比如标题一,标题二,段落等
伪类 可以对某一个特定的对象做设置,比如一个表格,一张图片。伪类还可以同时设置多个标签,比如同时设置body,td,h1的属性。
它能对网页的字体,背景,颜色和特殊效果以精确的控制,便于轻松的布局页面。css分为 类、标签,高级(也叫伪类)三种类型,css代码可以内嵌于一个html页面内,也可以独立成一个css文件,然后被html页面所引用
类 是可以应用于任何标签,是一种自定义的css类型,类的名字是以点开始的。
标签 是重新定义特定标签的外观,比如标题一,标题二,段落等
伪类 可以对某一个特定的对象做设置,比如一个表格,一张图片。伪类还可以同时设置多个标签,比如同时设置body,td,h1的属性。
内嵌到html的 标签css 代码如下:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title
>
<style type="text/css">
<!--
h1 {
font-size: 16px; \\设置字体大小
font-weight: bolder; \\设置字体加粗
color: #FF0000; \\设置字体颜色
text-align: center; \\设置居中
}
-->
</style>
</head>
内嵌到html的 类css 代码如下:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
<!--
.example {
font-family: "宋体";
font-size: 12px;
font-weight: normal;
color: #000000;
}
-->
</style>
</head>
<body>
</body>
</html>
独立的css文件,包含标签和类和伪类的css文件代码文件名为 example.css:
example1 {
font-family: "宋体";
font-size: 12px;
font-weight: normal;
color: #000000;
}
.example2 {
font-family: "宋体";
font-size: 12px;
font-weight: normal;
text-transform: capitalize;
color: #999999;
}
body,td,h1 {
font-family: "宋体";
font-size: 16px;
color: #99FF00;
}
html调用css文件的两种方法,代码如下:
1、连接
<head>
<link href="example.css" rel="stylesheet" type="text/css" />
</head>
2、导入
<head>
<style type="text/css">
<!--
@import url("example.css");
-->
</style>
</head>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title
>
<style type="text/css">
<!--
h1 {
font-size: 16px; \\设置字体大小
font-weight: bolder; \\设置字体加粗
color: #FF0000; \\设置字体颜色
text-align: center; \\设置居中
}
-->
</style>
</head>
内嵌到html的 类css 代码如下:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
<!--
.example {
font-family: "宋体";
font-size: 12px;
font-weight: normal;
color: #000000;
}
-->
</style>
</head>
<body>
</body>
</html>
独立的css文件,包含标签和类和伪类的css文件代码文件名为 example.css:
example1 {
font-family: "宋体";
font-size: 12px;
font-weight: normal;
color: #000000;
}
.example2 {
font-family: "宋体";
font-size: 12px;
font-weight: normal;
text-transform: capitalize;
color: #999999;
}
body,td,h1 {
font-family: "宋体";
font-size: 16px;
color: #99FF00;
}
html调用css文件的两种方法,代码如下:
1、连接
<head>
<link href="example.css" rel="stylesheet" type="text/css" />
</head>
2、导入
<head>
<style type="text/css">
<!--
@import url("example.css");
-->
</style>
</head>
转载于:https://blog.51cto.com/linuxguest/455380