CSS元素选择器 element selector(type selector)

http://www.w3school.com.cn/css/css_selector_type.asp

元素选择器

最常见的 CSS 选择器是元素选择器。换句话说,文档的元素就是最基本的选择器。

如果设置 HTML 的样式,选择器通常将是某个 HTML 元素,比如 p、h1、em、a,甚至可以是 html 本身:

设置html黑色,h1蓝色,h2银色

html {color:black;}
h1 {color:blue;}
h2 {color:silver;}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>CSS Test Website</title>
    <style type="text/css">
        html {
            color: black;
        }

        h1 {
            color: blue;
        }

        h2 {
            color: silver;
        }
    </style>
</head>
<body>
    <h1>This heading 1</h1>
    <h2>This heading 2</h2>
    <p>This is a normal paragraph.</p>
</body>
</html>

测试

尝试将html设置为red之后:html仅仅针对文本,无法对title起作用

取消h1的蓝色,设置paragraph为蓝色

html {color:black;}
p {color:blue;}
h2 {color:silver;}

xml文档设置样式

默认的显示

<?xml version="1.0" encoding="utf-8" ?>
<note>
  <to>George</to>
  <from>John</from>
  <heading>Reminder</heading>
  <body>Don't forget the meeting!</body>
</note>

显示效果

设置css样式,并且在xml中引用样式文件

在xml中引用样式文件的时候,先输入<,然后输入? ,webstorm会自动进行补全

引用方式是

<?xml-stylesheet type="text/css" href="note.css"?>

另外,关于xml中标签自定义的说明,可以查看http://www.w3school.com.cn/xml/xml_intro.asp 

通过 XML 您可以发明自己的标签

最后,相关文件已经上传到github

https://github.com/ChuckTest/CSSTest

原文地址:https://www.cnblogs.com/chucklu/p/6882972.html