css 相关
文章目录
CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明
CSS声明总是以分号(;)结束,声明总以大括号({})括起来
为了让CSS可读性更强,你可以每行只描述一个属性
CSS注释以 /* 开始, 以 */ 结束
CSS Id 和 Class
id 选择器可以为标有特定 id 的 HTML 元素指定特定的样式。HTML元素以id属性来设置id选择器,CSS 中 id 选择器以 “#” 来定义。
ID属性不要以数字开头,数字开头的ID在 Mozilla/Firefox 浏览器中不起作用
class 选择器用于描述一组元素的样式,class 选择器有别于id选择器,class可以在多个元素中使用。class 选择器在HTML中以class属性表示, 在 CSS 中,类选择器以一个点"."号显示
类名的第一个字符不能使用数字!它无法在 Mozilla 或 Firefox 中起作用
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
<style>
.center
{
text-align:center;
}
</style>
</head>
<body>
<h1 class="center">标题居中</h1>
<p class="center">段落居中。</p>
</body>
</html>
# 另一种
<style>
h1.center
{
text-align:center;
}
</style>
</head>
<body>
<h1 class="center">这个标题不受影响</h1>
<p class="center">这个段落居中对齐。</p>
CSS 背景属性用于定义HTML元素的背景。
CSS 属性定义背景效果:
- background-color
- background-image
- background-repeat
- background-attachment
- background-position
ckground-repeat
- background-attachment
- background-position