批改状态:合格
老师批语:
<head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Document</title><!-- 外部样式表也叫公共样式表,可多个页面引用 --><link rel="stylesheet" href="css/style.css" /></head>
<head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Document</title><style>/* 内联样式通过<style>标签声明,只应用于当前页面 */ul>li {background-color: chartreuse;}</style></head>
<head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Document</title></head><body><!--style样式属性只作用于当前元素 --><h1 style="color: red">css样式</h1></body>
/* 定义标签元素 */li {background-color: red;}
效果截图
<style>ul li p {background-color: darkcyan;}</style><ul><li><dl><dt>标签1</dt></dl><p>这里是一个P标签</p></li><li id="site">标签2</li><li>标签3</li><li class="top">标签4</li><li>标签5</li><li>标签6</li><li>标签7</li><li>标签8</li></ul>
效果截图
<style>ul>li {background-color: lemonchiffon;}</style><ul><li><dl><dt>标签1</dt></dl><p>这里是一个P标签</p></li><li id="site">标签2</li><li>标签3</li><li class="top">标签4</li><li>标签5</li><li>标签6</li><li>标签7</li><li>标签8</li><ul><li>内容</li></ul></ul>
效果截图
类选择器
<style>/* 根据类定义元素 */.top {background-color: blueviolet;}</style><ul><li>标签1</li><li>标签2</li><li>标签3</li><li class="top">标签4</li><li>标签5</li><li>标签6</li><li>标签7</li><li>标签8</li></ul>
效果截图
<style>/* 根据id定义元素 */#site {background-color: crimson;}</style><ul><li>标签1</li><li id="site">标签2</li><li>标签3</li><li class="top">标签4</li><li>标签5</li><li>标签6</li><li>标签7</li><li>标签8</li></ul>
效果截图
<style>.top ~ li {background-color: darkcyan;}</style><ul><li>标签1</li><li id="site">标签2</li><li>标签3</li><li class="top">标签4</li><li>标签5</li><li>标签6</li><li>标签7</li><li>标签8</li></ul>
效果截图
<style>.top + li {background-color: darkcyan;}</style><ul><li>标签1</li><li id="site">标签2</li><li>标签3</li><li class="top">标签4</li><li>标签5</li><li>标签6</li><li>标签7</li><li>标签8</li></ul>
效果截图
<style>/* 定义第一个元素 */ul > li:first-of-type {background-color: chocolate;}</style>
效果截图
<style>/* 定义最后一个元素 */ul > li:last-of-type {background-color: violet;}</style>
效果截图

定义偶数元素 :nth-of-type(2n)
<style>/* 定义偶数元素 */ul > li:nth-of-type(2n) {background-color: chocolate;}</style>
效果截图
定义奇数元素 :nth-of-type(2n-1)
<style>/* 定义奇数元素 */ul > li:nth-of-type(2n-1) {background-color: green;}</style>
效果截图
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号