CSS学习笔记1

基本语法
在这里插入图片描述
键值对形式书写

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
    	/*选择器{样式}*/
    	p {
    		color : red;
    		font-size : 12px;
    	}
    </style>
    <title>Document</title>
</head>
<body>
    <p>阿巴阿巴吧</p>
</body>
</html>
选择器
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
       /* 标签选择器 : 标签名 */
        p {
        color : rgb(255, 0, 0);
        font-size: 20px;
        }
        /* 类选择器 */
        .green {
            color: rgb(0, 255, 128);
        }
        .fz { 
            font-size: 16px;
        }
        #pink {
            color: pink;
        }
        /* 通配符选择器 * 选择所有 */
        * {
            font-weight: 200;
        }
    </style>
    <title>Document</title>
</head>
<body>
    <p>阿巴阿巴吧</p>
    <p class="green">阿巴巴巴</p>
    <!-- 多类名的使用 -->
    <p class="green fz">abaabaa</p>
    <p id = "pink">abababa</p>
</body>
</html>
基础选择器作用特点使用情况用法
标签选择器可以选出相同的标签不能差异化选择使用情况p{color : red}
类选择器可以选出1个或多个标签可以根据需求选择非常多.nav{color :red}
id选择器一次只能选择一个标签ID属性只在HTML中出现一次一般和js搭配#nav{color:red}
通配符选择器选择所有标签选择的太多,有部分不需要特殊情况使用*{color :red}

CSS中的字体属性

属性名样式用法
font-family字体p{font-family:“微软雅黑”,‘Times New Roman’,Times} 依据使用者设备是否安装了该字体而递推使用,常用字体‘微软雅黑’,tahoma,arial
font-size字体大小p{font-size:20px},标题标签需要特定指定大小
font-weight字体粗细p{font-weight:bold}参数 bold、bolder、lighter、100、200、30、、400、500、600、700、800、900
font-style字体样式p{font-style:normal} normal为默认风格 italic斜体风格

字体复合属性:
font:font-style   font-weight   font-size/line-height   font-family
在这里插入图片描述
不需要设置的值可以省略,但font-size与font-style不能省略,否则font不能起作用。

CSS文本属性

1.文本颜色

color

div  {
	color : red;
}
2.文本对齐

text-align

h1 {
	text-align: center;
}

属性参数:left、center、right

3.装饰文本

text-decoration

div {
	text-decoration : underline;
}
属性值描述
none默认,没有装饰
underline下划线
overline上划线
line-through删除线。(不常用)
4.文本缩进

text-indent
首行缩进

p{
	text-indent : 20px;
}

2em当前元素两个文字大小的距离

p{
	text-indent : 2em;
}
5.行间距

line-height

p{
	line-height:26px;
}

这里的26px包括了文本的高度

CSS的三种样式表

1.内部样式表 写到html页面内部,是将所有的CSS代码抽取出来,单独放到< style>标签中。 也叫嵌入式引入 2.行内样式表 在元素标签内部的style属性中设定CSS样式
<div style="color : red; font-size: 12px;">
	楼上的电钻突突突
</div>

3.外部样式表
样式单独写在css文件中,之后把css文件引入到html页面中使用。
a.创建后缀名为css的文件,将所有的css代码放入其中
b.在html文件中使用< link>标签来引入css文件

< link rel="stylesheet" href="文件路径">
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值