3.12-3 html

css层叠样式

层叠样式

(1)定义:css是一种用来表现html或xml等文件样式的计算机语言。

(2)css 不仅可以静态的修饰网页,还可以配合各种动态对网页元素进行格式化;

(3)层叠样式表有两种方法:

第一种:在head中加上style属性

代码:

<style type="text/css">

p{

color: red;

}

</style>

案例:

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>层叠样式</title>

<style type="text/css">

p{

color: red;

}

</style>

</head>

<body>

<p>1</p>

<p>2</p>

<p>3</p>

<em>a</em>

<i>i</i>

<h1>标题</h1>

</body>

</html>

第二种:通过外链方式

在css中新建一个css文件,在css文件中写内容

在使用link 通过外链方式实现

代码:

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>层叠样式</title>

<!--<style type="text/css">

p{

color: red;

}

</style>-->

<link rel="stylesheet" type="text/css" href="../css/渲染.css"/>

</head>

<body>

<p>1</p>

<p>2</p>

<p>3</p>

<em>a</em>

<i>i</i>

<h1>标题</h1>

</body>

</html>

二、选择器

(1)id选择器 # id

代码:

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>层叠样式</title>

<style type="text/css">

#dcs{

color: red;

}

</style>

<!--<link rel="stylesheet" type="text/css" href="../css/渲染.css"/>-->

</head>

<body>

<p id=dcs>1</p>

<p>2</p>

<p>3</p>

<em id=dcs>a</em>

<i>i</i>

<h1>标题</h1>

</body>

</html>

(2)class选择器(.)

(3)标签选择器

比如:i 标签

(4)组合标签

(5)伪类选择器

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>层叠样式</title>

<style type="text/css">

p{

color: red;

}

p:hover{

color: blue;

cursor: pointer;

}

</style>

<!--<link rel="stylesheet" type="text/css" href="../css/渲染.css"/>-->

</head>

<body>

<p id=dcs>1</p>

<p class=a>2</p>

<p>3</p>

<em id=dcs>a</em>

<i>i</i>

<h1>标题</h1>

</body>

</html>

三、层叠样式中的内容可以多样化

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>层叠样式</title>

<style type="text/css">

p{

color: red;

font-size: 50px;

font-family: "微软雅黑" ;

font-style: italic;

font-weight: bold;

text-align: center;

cursor: pointer;

text-decoration: underline;

}

</style>

<!--<link rel="stylesheet" type="text/css" href="../css/渲染.css"/>-->

</head>

<body>

<p id=dcs>1</p>

<p class=a>2</p>

<p>3</p>

<em id=dcs>a</em>

<i>i</i>

<h1>标题</h1>

</body>

</html>

相关推荐
chh5639 小时前
从 BERT 到大模型:让模型从“会接龙”到“会回答
人工智能·深度学习·bert
TomEval9 小时前
【测AI】第26篇:线上模型监控与告警体系 — 测试不是终点
人工智能·python·功能测试·ai
prince_zxill10 小时前
PEP 751 pylock.toml 实测:pip 26.3 装 6 个包版本全钉死,但 [web] 选不中任何东西
python·pip·依赖管理·pep 751
ZhengEnCi10 小时前
AI 总模仿代码库里的过时写法怎么办:先清坏样例,再用类型与测试让 AI 无法犯错
人工智能·ai编程
一只爱撸猫的程序猿10 小时前
五周、两个开源仓库、九次拦截之后:AI 时代程序员缺的到底是什么
人工智能·后端·开源
GitCode官方11 小时前
开源鸿蒙跨平台直播|AI 时代,用 cj-tauri 开发鸿蒙 PC 应用
人工智能·华为·harmonyos·atomgit
老金带你玩AI11 小时前
GPT-6.2更强更便宜了,为什么还有人骂?
人工智能
Thanks_ks11 小时前
Python 的垃圾回收——引用计数撑起日常,分代回收收拾残局
python·内存管理·垃圾回收·循环引用·引用计数·gc 模块·weakref
CyrusYiVPP11 小时前
实测 uv 0.13.7:同一套包,pip 装 94 秒,它只用 19 秒
人工智能·python
泯泷12 小时前
OpenClaw 退潮背后,是 AI 圈“技术自嗨”的终结
人工智能·chatgpt·llm