CSS层叠样式表、CSS的选择器、CSS的样式规则

目录

一、CSS层叠样式表

1.基本语法

 2.使用方法

二、CSS的选择器

(1)标签名选择器

(2)类选择器

(3)id选择器

(4)通配选择符

三、CSS的样式规则

1.字体规则

 2.列表样式

3.表格样式


一、CSS层叠样式表

1.基本语法

<STYLE  type="text/css">

 P  {color:red; font-size:30px; font-family:隶书;}

……

</STYLE>

 2.使用方法

 (1)行内嵌入式:给标签添加style属性,用来设置样式(只对当前嵌入的标签有效)

<p style="color: cyan; font-size: 45px;">西安邮电大学</p>

 (2)页面嵌入式:在页面中使用<style></style>定义不同的样式规则

<style>
    body{/* 表示body中的所有内容都居中 */
		text-align: center;  
		}
				
	p{
		color: red; /*color表示文字的颜色*/
		font-size: 45px; /*font-size表示字号*/
	 }
</style>
<body>
	<p>西安邮电大学</p>
	<p>湖南湘潭大学</p>
</body>

 (3)导入css文件的方式:推荐使用

第一步:创建扩展名为.css的样式文件

第二步:在页面中通过<link>标签将外部的css文件链接起来

<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">
    <title>Document</title>
    <link rel="stylesheet" href="../css/table.css">
</head>

二、CSS的选择器

CSS的选择器:在CSS中定位页面中的标签(控件)

(1)标签名选择器

 标签名{
         样式规则(属性): 值;
            }

body{  /* 表示body中的所有内容都居中 */
    text-align: center;  
}

p{
    color: blue; /*color表示文字的颜色*/
    font-size: 45px; /*font-size表示字号*/
}

(2)类选择器

在页面中给标签添加class属性,标签的class属性值可以重复

 .类名(标签的class属性值){
          样式规则(属性): 值;
            }

.p1 {
    color: rgba(0, 0, 0 , 0.5)
}
.p2 {
    color: rgb(100, 50, 255);
}

(3)id选择器

在页面中给标签添加id属性,标签的id属性值不能重复

#id{
      样式规则(属性): 值;
            }

#ht{
    color: rgba(141, 49, 49, 0.5);
    font-style: italic;
    font-size: 35px;
    font-family: '隶书';
    font-weight: 900;
}

(4)通配选择符

*,代表所有元素

*{
     样式规则(属性): 值; 
            }

三、CSS的样式规则

1.字体规则

文本属性

说 明

font-weight

字体粗细

line-height

文字行高

word-spacing

单词间距

letter-spacing

字母间距

text-decoration

文本样式

<style>
p
{
  color:#888888;
  font-size:14px;
  word-spacing:10px;
  letter-spacing:2px;
  font-weight:700;
  line-height:1.5;
  width:500px;
}
</style>
</head>
<body>
<p>
Abram went north out of Egypt to the southern part of Canaan with his wife and everything he owned, and Lot went with him. 
	</p>

背景属性

说 明

background-color

设置背景颜色

background-image

设置背景图像

background-repeat

设置一个指定的图像如何被重复

可取值repeat-xrepeatno-repeatrepeat-y

2.列表样式

属性说明
   list-style-position设置项目符号和文本的位置
outside默认值,列表项目符号放置在文本以外,且环绕文本不根据符号对齐
 inside列表项目符号放置在文本以内,且环绕文本根据符号对齐
 list-style-image指定项目符号的图像  
 list-style-type指定项目符号的类型
   list-style指定列表样式
body{
    text-align: center;
}
li{
    /* list-style-position: inside;
    list-style-type:lower-roman; */
    list-style: url('../images/f4.png') inside none;
}

 

3.表格样式

属性

CSS名称说明

边界属性

margin-top

设置对象的上边距

margin-right

设置对象的右边距

margin-bottom

设置对象的下边距

margin-left

设置对象的左边距

边框属性border-spacing指定单元格之间的距离,不能是负值
border-collapse指定单元格的边框是否合并,取值有两个
separate单元格边框独立,默认值
collapse相邻单元格的边框合并
border-color边框颜色
border-width border-width
border-style边框线的样式
border-radius边框的弧度

填充属性

padding-top

设置内容与上边框之间的距离

padding-right

设置内容与右边框之间的距离

padding-bottom

设置内容与下边框之间的距离

padding-left

设置内容与左边框之间的距离

body{
    text-align: center;
}
table {
    border-spacing: 25px;
    border-collapse:collapse;
    border-color: blue;
    border-width: 2px;
    border-style:dashed;
    border-radius: 15px;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陛下,再来一杯娃哈哈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值