之前作j2ee,超级烦写css,属性太多,看来仍是绕回来了!css
一、元素选择器html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>师然学习笔记</title>
<!--描述:元素选择器 -->
<style type="text/css">
div{
background-color: red;
font:italic normal bold 14pt normal 楷体_GB2312;
}
</style>
</head>
<body>
<divr>
师然学习JAVA
</div>
</body>
</html>java
效果以下:android
二、ID选择器学习
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>师然学习笔记</title>
<!--描述:元素选择器 -->
<style type="text/css">
div{
background-color: red;
font:italic normal bold 14pt normal 楷体_GB2312;
}
#shiran{
width:200px;
height:30px;
background-color: #ddd;
padding:3px
}
</style>
</head>
<body>
<div id="shiran">
师然学习JAVA
</div>
</body>
</html>orm
效果以下:htm
若是只想对某一id的某一个元素起做用,能够这样写blog
例如:只对多个div元素中的某一个id为shiran的元素起做用:it
div#shiran{io
width:200px;
height:30px;
background-color: #ddd;
padding:3px
}
三、class选择器
我之前会叫它“类选择器”,别人也这么叫,可是这样的称呼并不合适,它和类没有关系。只是好像把一些属性放到了一块儿而已,谁用均可以。
这个class选择器也和ID选择器同样,能够写上元素名。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>师然学习笔记</title>
<style type="text/css">
.shiranClass{
background-color: red;
}
</style>
</head>
<body>
<div class="shiranClass">师然学习JAVA</div>
</body>
</html>
效果以下:
四、包含选择器
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>师然学习笔记</title>
<style>
div{
font-family: "微软雅黑";
background-color: yellow;
}
div.shiran{
font-family: "微软雅黑";
background-color: red;
}
</style>
</head>
<body>
<div>师然学java</div>
<div>
<section>
<div class="shiran">师然学HD5</div>
</section>
</div>
<p class="shiran">师然学iOS</p>
</html>
效果以下:
五、子选择器
子选择器和包含选择器有点像,区别在于:
包含选择器的目标元素还要在父元素下就能够,孙子元素也能够。
可是子选择器就必须是儿子,也就是说目标元素必须是直接子元素,孙子都不行。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>师然学习笔记</title>
<style type="text/css">
div{
width: 200px;
height: 30px;
background-color:red ;
margin: 5px;
}
div>.shiran{
width: 300px;
height: 40px;
background-color:yellow ;
margin: 10px;
}
</style>
<body>
<div>我是1号DIV</div>
<div><p class="shiran">我是2号DIV</p></div>
<div><section><p class="shiran">我是3号DIV</p></section></div>
</body>
</html>
效果以下:
六、兄弟选择器
这个有点难理解,我理解的意思是这样,目标选择器做用的位置元素在匹配的某选择器的 后面。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>师然学习笔记</title>
<style type="text/css">
#android ~ .long{
background-color: #00FF00;
}
</style>
</head>
<body>
<div>
<div>师然学习Java</div>
<div class="long">师然学习H5</div>
<div id="android">师然学习iOS</div>
<p class="long"> 师然学习安卓</p>
<div class="long">师然学习.NET</div>
</div>
</body>
</html>
看代码,android是个人第一个选择器,是一个ID选择器,而后有一个class选择器叫long.
那么,再看个人几个html元素。在ID为android后面的元素,若是class是long,这个才生效。