当前位置: 首页 > news >正文

CSS学习笔记

 【1】CSS样式规则

【2】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,intial-scale=1.0"/>
    <title>行内式</figure></title>
</head>
<body>
	<h2 style="font-size: 20px; color: red;">古之学者必有师。师者,所以传道授业解惑也。</h2>
</body>
</html>

 效果展示

2、内嵌式

<!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,intial-scale=1.0"/>
    <title>内嵌式</title>
	<style type="text/css">
		h2{text-align: center;}
		p{
		font-size: 16px;
		color: red;
		text-decoration: underline;
		}
	</style>
</head>
<body>
	<h2>《劝学》片段</h2>
	<p>
		青,取之于蓝,而青于蓝;冰,水为之,而寒于水。
		木直中绳,輮以为轮,其曲中规。虽有槁暴,不复挺者,輮使之然也。
		故木受绳则直,金就砺则利,君子博学而日参省乎己,则知明而行无过矣。
	</p>
</body>
</html>

效果展示 

3、链入式 

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"/>
    <title>链入式</title>
	<link href="css/第三次实践.css"  rel="stylesheet" type="text/css"/>
	
</head>
<body>
	<h2>《劝学》片段</h2>
	<p>
		青,取之于蓝,而青于蓝;冰,水为之,而寒于水。
		木直中绳,輮以为轮,其曲中规。虽有槁暴,不复挺者,輮使之然也。
		故木受绳则直,金就砺则利,君子博学而日参省乎己,则知明而行无过矣。
	</p>
</body>
</html>

CSS 

h2{text-align:center;}

p{
	font-size: 16px;
	color:blue;
	text-decoration:underline;
}

 效果展示

4、导入式

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"/>
    <title>链入式</title>
	<style type="text/css">
		@import url(css/第三次实践.css);
		h2{color: red;}
	</style>
	
</head>
<body>
	<h2>《劝学》片段</h2>
	<p>
		青,取之于蓝,而青于蓝;冰,水为之,而寒于水。
		木直中绳,輮以为轮,其曲中规。虽有槁暴,不复挺者,輮使之然也。
		故木受绳则直,金就砺则利,君子博学而日参省乎己,则知明而行无过矣。
	</p>
</body>
</html>

CSS

h2{text-align:center;}

p{
	font-size: 16px;
	color:darkgreen;
	text-decoration:underline;
}

效果展示

【3】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"/>
    <title>标签选择器和类选择器</title>
	<style type="text/css">
		/*标签选择器*/
		p{
			text-decoration: underline;
			font-family: "微软雅黑";
		}
		/*类选择器*/
		.red{color: red;}
		.green{color: greenyellow;}
		.font22{font-size: 22px;}
	</style>
	
</head>
<body>
	<h2 class="red">二级标题文本</h2>
	<p class="green font22">段落一文本内容</p>
	<p class="red font22">段落二文本内容</p>
	<p>段落三文本内容</p>
</body>
</html>

效果展示

2、id选择器

<!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"/>
    <title>id选择器</title>
	<style type="text/css">
		#bold{font-weight: bold;}
		#font24{font-size:24px; }
	</style>
	
</head>
<body>
	<p id="bold">段落一设置粗体文字</p>
	<p id="font24">段落二设置字号为24px。</p>
	<p id="font24">段落三设置字号为24px。</p>
	<p id="bold font24">段落四设置粗体文字,设置字号为24px。</p>
</body>
</html>

效果展示

4、通配符选择器和交集选择器

<!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"/>
    <title>通配选择器和交集选择器</title>
	<style type="text/css">
		*{text-decoration: underline;} /*通配选择器*/
		p{color: red;}/*标签选择器*/
		.special{color: blue;}/*类选择器*/
		p.special{color: green;}/*交集选择器*/
	</style>
	
</head>
<body>
	<p>段落一,标签选择器的作用对象(红色)</p>
	<p class="special">段落二为绿色,交集选择器的作用对象</p>
	<h2 class="special">标题为蓝色,交集选择器不影响选择器的单独使用。</h2>
	<p>
		所有内容都有下划线,因为通配选择器的作用范围是所有标签
	</p>
</body>
</html>

 效果展示

5、并集选择器

<!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"/>
    <title>并集选择器</title>
	<style type="text/css">
		h2,h3,p{color: red;font-size: 14px;}/*由不同的选择器组成的并集选择器*/
		h3,.special,#one{text-decoration: underline;}/*由标签选择器、类选择器、id选择器组成的并集选择器*/
		
	</style>
	
</head>
<body> 
	<h2>二级标题,红色,14px大小</h2>
	<h3>三级标题,红色,大小14px,有下划线</h3>
	<p class="special">段落一含类special,有下划线,红色,大小14px</p>
	<p>段落二,红色,大小14px</p>
	<p id="one"> 红色,14px,有下划线</p>
</body>
</html>

效果展示 

6、后代选择器

<!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"/>
    <title>后代选择器</title>
	<style type="text/css">
		p strong{
			color: blueviolet;
		}
		
		p strong em {
			color: blue;
		}
		
		strong{
			color: hotpink;
		}
	</style>
	
</head>
<body> 
	<p>
		天下难事,<strong>必作于易。</strong>
	</p>
	
	<p>
			天下难事,<strong>必作于易。
			天下兴亡,<em>匹夫有责。</em></strong>
	</p>
	
	<strong>天下大事,必作于细</strong>
</body>
</html>

效果展示

相关文章:

  • MySQL 入门大全:数据类型
  • 题单:排队接水1
  • ORACLE RAC ASM双存储架构下存储部分LUN异常的处理
  • 基于springboot的电影院管理系统(源码+lw+部署文档+讲解),源码可白嫖!
  • 4-Taurus平台 LCD驱动支持DRM框架移植
  • Spring事务失效场景
  • android音频概念解析
  • mybatisplus雪花算法id重复日记
  • PicFlow:一个图片处理与上传工作流工具(图床上传工具)
  • Debian12生产环境配置笔记
  • systemctl restart 和 systemctl reload 和 systemctl daemon-reload 对比 笔记250322
  • SOFABoot-10-聊一聊 sofatboot 的十个问题
  • QEMU 引导时分离内核和文件系统
  • Collectors.toList / list 转 list
  • Netty——BIO、NIO 与 Netty
  • 第十六章:Specialization and Overloading_《C++ Templates》notes
  • ‌App Store美学竞争:如何通过广告素材分析实现ASO弯道超车‌
  • 基于Spring Boot 的在线教育系统(源码+lw+部署文档+讲解),源码可白嫖!
  • PRODIGY: “不折腾人”的蛋白-蛋白/蛋白-小分子结合能计算工具
  • SEO长尾关键词精准布局
  • 加拿大温哥华发生驾车冲撞人群事件,加拿大总理发声
  • 中央纪委办公厅公开通报3起整治形式主义为基层减负典型问题
  • 中国太保一季度净赚96.27亿元降18.1%,营收同比下降1.8%
  • 农贸美学、业态再构、智能管理,今天的菜市场不止有菜
  • 现场|贝聿铭上海大展:回到他建筑梦的初始之地
  • “谁羽争锋”全国新闻界羽毛球团体邀请赛在厦门开赛