CSS选择器相关知识

一,派生选择器ide

li strong {
    font-style: italic;
    font-weight: normal;
  }

指定一个元素中的子元素的样式。这种的选择器不会由于层级关系失效。若是li中包裹了其余包裹了strong的元素,那么strong元素的样式仍是生效的。code

h1 > strong {color:red;}

和派生选择器的功能差很少,不一样的是,多层包裹的话不会生效。只有在h1中包裹的strong元素才能生效。orm

h1 + p {margin-top:50px;}

相邻兄弟选择器。拥有同一个父级元素的兄弟元素都能对该样式声明生效。input

二,id选择器it

#sidebar p {
	font-style: italic;
	text-align: right;
	margin-top: 0.5em;
	}

上面的时id选择器和派生选择器结果,获得的结果就是,id为sidebar的元素中的p元素样式为上述的样式。class

三,类选择器样式

.fancy td {
	color: #f60;
	background: #666;
	}

这个例子的意思为,td的父级元素的class等于fancy,那么这个父元素中包裹的td元素都会使用到上述的margin

td.fancy {
	color: #f60;
	background: #666;
	}

基于td元素使用了fancy样式。top

四,属性选择器di

[title]{
color:red;
}
input[type="text"]
{
  width:150px;
  display:block;
  margin-bottom:10px;
  background-color:yellow;
  font-family: Verdana, Arial;
}

input[type="button"]
{
  width:120px;
  margin-left:35px;
  display:block;
  font-family: Verdana, Arial;
}
相关文章
相关标签/搜索