css 引入方式与选择器
今天学习了css的引入方式和css的选择器
Css引入方式总共四种分别是:
1.<link rel=”realstyle” type=”text/css” href=”css.css”>
rel 表明连接的文件与html文档之间的关系
type 是表明文件类型
href 指向链接的css文件
2.在html文档的head部分直接写入css文档。
<style type="text/css">
div{margin: 0;padding: 0;border:1px red solid;}
</style>
3. 直接在html标签里写入对这个标签的css控制
Eg:<div style="border:1px red solid;">测试信息</div>
4.使用@import引入css文件
1:在head里使用的时候:
<style type="text/css">
@import url(my.css);
</style>
2:在css文件里使用。
(@import本身是一个css命令。)
选择器总共有五种分别:
1.类选择器
在 CSS 中,类选择器以一个点号显示:
HTML:
<div class="test">测试代码</div>
CSS:
.test {color:red;border:1px blue solid;}
注意:类名的第一个字符不能使用数字!它无法在 Mozilla 或 Firefox 中起作用。
2.id 选择器
id 选择器可以为标有特定 id 的 HTML 元素指定特定的样式。
id 选择器以 "#" 来定义。
HTML:
<div id="test">测试代码</div>
CSS:
#test {color:red;border:1px blue solid;}
注意:id 属性只能在每个 HTML 文档中出现一次。
3.后代选择器
通过依据元素在其位置的上下文关系来定义样式,你可以使标记更加简洁。
HTML:
<div class="test">
<span><img src="xxx" alt="示例图片"/></span>
</div>
CSS:
.test span img {border:1px blue solid;}
div span img {border:1px blue solid;}
4.群组选择器
CSS:
.test1,span,test2 {border:1px blue solid;}
div,span,img {border:1px blue solid;}
5.标签选择器
CSS:
div {color:red;border:1px blue solid;}
span {float:right;}
今天还学到了一些选择器的优先级的知识,感觉这些内容很容易的就理解了,不知道以后运用到实战中会怎么样,还是拭目以待,但是要想学牢固还是要通过大量的练习才能达到得心应手。
相关文档:
1.图片的垂直居中
.box
{
/*非IE的主流浏览器识别的垂直居中的方法*/
display: table-cell;
vertical-align: middle; /*设置水平居中*/
text-align: center;
/* 针对IE的Hack */
*display:block;
......
效果图:
csstest.css
*{
margin-left:0;
margin-top:0;
font-size:12px;
color:White;
}
#biaoge
{
/*对ID为biaoge的标签使用此CSS*/
width:405px; /*列宽100,加上五个为1的边距,四列就是405*/
&nbs ......
这个系列可能新手读起来比较慢,但我尽量用易懂的方式讲解,因为我曾经是初学者,我知道大家想知道什么。一张网面其实页面内容是比较重要的,图像是属于锦上添花,当然网页的排版也很重要。在CSS揭秘学习的第一站,首先要学习一下文字和文本,让大家对css有个初步的认识。
&nb ......
盒子标签和属性对照
CSS语法(不区分大小写)
JavaScript语法(区分大小写)
border
border
border-bottom
borderBottom
border-bottom-color
borderBottomColor
border-bottom-style
borderBottomStyle
border-bottom-width
borderBottomWidth
border-color
borderColor
border-left
borderLeft
border ......