Home > Web Front-end > HTML Tutorial > css 标签选择器、id选择器、类选择器实例

css 标签选择器、id选择器、类选择器实例

WBOY
Release: 2016-06-01 09:53:03
Original
3082 people have browsed it

1:标签选择器

标签选择器,是所有带有某种标签的都生效。这里以p为例,也就是所有的带有p标记的都会这样的样式

实例:选择所有

元素 :

<code class="language-html">


<style>
p
{
background-color:yellow;
}
</style>



<h1>Welcome to My Homepage</h1>

<div>
<p id="firstname">My name is Donald.</p>
<p id="hometown">I live in Duckburg.</p>
</div>

<p>My best friend is Mickey.</p>


</code>
Copy after login

在线运行

 

2:id选择器

注意id选择器是唯一的,因为只有id="yy"的才有这种样式,而一个页面里元素的Id必须是唯一的,所以。。。你懂得id选择器以#开头用法是:id=""

实例:为 id="firstname" 元素添加指定样式:

<code class="language-html">


<style>
#firstname
{
background-color:yellow;
}
</style>



<h1>Welcome to My Homepage</h1>

<div class="intro">
<p id="firstname">My name is Donald.</p>
<p id="hometown">I live in Duckburg.</p>
</div>

<p>My best friend is Mickey.</p>


</code>
Copy after login

在线运行

 

3:类选择器.

类选择器以.开头,只要把元素的class="" 就能表现为这种样式了用法是:class=""

实例:

<code class="language-html">


<style>
.intro
{
background-color:yellow;
}
</style>



<h1>Welcome to My Homepage</h1>

<div class="intro">
<p>My name is Donald.</p>
<p>I live in Duckburg.</p>
</div>

<p>My best friend is Mickey.</p>


</code>
Copy after login

在线运行

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template