CSS基础教程之选择器_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:18:24
Original
974 people have browsed it

分类:WEB前端时间: 2015年9月8日

在CSS中,选择器用于选择需要添加样式的元素,简单的讲,就是确定你要把样式给那个元素。在我们写web前端的时候,选择器的使用是非常频繁的,合理的使用选择器会精简大量的代码。CSS选择器大致的归类为基础选择器和符合选择器两类。

1、基础选择器:

a、html标签选择器:

标签{属性:属性值}

div、p、h1、span……

b、class 类选择器,可以共用重复:

.name {属性:属性值}

标签中有class=”name”的元素

c、id选择器: 唯一性

#name{属性:属性值}

标签中有id=”name”的元素

d、属性选择器

*[title] {属性:属性值}

所有包含标题(title)的元素

e、通配符选择器,所有的元素:

* {属性:属性值}

例:* {margin:0; padding:0}

2、复合选择器

a、 后代选择器:

A B { 属性:属性值}

注:A指父级选择器 B指子级选择器

b、伪类选择器:

a:link {属性:属性值} 默认

a:visited {属性:属性值} 访问过的链接

a:hover {属性:属性值} 鼠标经过

a:active {属性:属性值} 激活状态(选中时的状态)

注:顺序不能错 l v h a,还有一个a {属性:属性值} ,这个也要写,里面放超链接中相同属性,不同属性分别写在不同的伪类选择器中。

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!