目录
前言
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。CSS不仅可以静态地修饰网页,还可以配合各种脚本语言动态地对网页各元素进行格式化。 [1]
CSS 能够对网页中元素位置的排版进行像素级精确控制,支持几乎所有的字体字号样式,拥有对网页对象和模型样式编辑的能力。
DIV是html的一个标签 css是一个样式表
提示:以下是本篇文章正文内容,下面案例可供参考
一、样式表类型
1.1 嵌入样式表
代码如下(示例):
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
.demo1{
color: red;
width: 100px;
height: 100px;
background: blue;
}
</style>
</head>
<body>
<div class="demo1">
demo1
</div>
</body>
</html>
1.2 外部样式
代码如下(示例):
<link rel="stylesheet" href="css/style.css"/>
@import url
@import url("g.css");
.demo1{
color: red;
width: 100px;
height: 100px;
background: blue;
}
二、注释
代码如下(示例):
/*13213 */ 注释内容
三、样式选择器
释义 | 属性 |
---|---|
元素选择器 | div{属性:值} |
ID选择器 | #id{属性:值} |
class选择器 | .类名{属性:值} |
子选择器 | 元数 空格 元素{属性:值} |
后代选择器 | 元数 > 元数{属性:值} |
属性选择器 | 元素[属性]{} |
通配符选择器 | *{属性:值} |
群组选择器 |
代码如下(示例):
<style>
body{
color:red;
font-family: "微软雅黑";
font-size: 14px;
}
.demo7{
font-variant:small-caps;
border: 1px solid red;
text-align: center;
}
.p1{
line-height: 30px;
text-indent:20px;
}
a{
text-decoration: none;
}
</style>
四、背景
属性 | 释义 |
---|---|
background-color | 规定要使用的背景颜色 |
background-position | 规定背景图像的位置 |
background-size | 规定背景图片的尺寸 |
background-repeat | 规定如何重复背景图像 |
background-origin | 规定背景图片的定位区域 |
background-clip | 规定背景的绘制区域 |
repeat | 默认 背景图像将在垂直方向和水平方向重复 |
repeat-x | 背景图像将在水平方向重复 |
repeat-y | 背景图像将在垂直方向重复 |
no-repeat | 背景图像将仅显示一次 |
inherit | 规定应该从父元素继承 background-repeat 属性的设置 |
background-attachment | 规定背景图像是否固定或者随着页面的其余部分滚动 |
background-image | 规定要使用的背景图像 |
inherit | 规定应该从父元素继承 background 属性的设置 |
代码如下(示例):
<style>
body{
/*background-color: #FFFF00;
background-image: url(img/1.jpg);
background-repeat: no-repeat;
background-attachment: fixed;
/*background-repeat:repeat-y;
background-repeat:repeat-x;*/
background: url(img/1.jpg) no-repeat fixed;
}
</style>