首页 > Web开发 > 详细

CSS 入门

时间:2014-02-09 15:59:21      阅读:435      评论:0      收藏:0      [点我收藏+]

简介
Cascading Style Sheets(级联样式表),是一种用来表现HTML或XML等文件央视的计算机语言。


选择器
id 选择器
     id 选择器可以为标有特定id的HTML 元素指定特定的样式。HTML元素以id属性来设置id选择器,CSS 中 id 选择器以“#” 来定义。以下的样式规则应用于元素属性 id="para1"
   

bubuko.com,布布扣
#para1
     {
          text-align:center;
          color:red;
     }
bubuko.com,布布扣

 
class 选择器
     class 选择器用户描述一组元素的样式,class 选择器可以在多个元素中使用。class 选择器在HTML中以class属性表示,在CSS中,类选择器以一个点“.”号表示:
     所有拥有center类的HTML元素均居中: .center {text-align:center;}
     所有拥有center类的P元素均居中: p.center {text-align:center;}


引入方式
行内式:即在表示的style属性中设定CSS样式。这种方式本质上没有体现出CSS得优势,不推荐。

bubuko.com,布布扣
 <html>
       <head>
              <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
              <title>Text Demo</title>
       </head>
       <body>
              <h1 style=color:white;background-color=blue;>
              This is a line of Text.
              </h1>
       </body>
 </html>
bubuko.com,布布扣

内嵌式:将对页面中各元素的设置几种写在<head>和</head>之间。对单一网页,还比较方便

bubuko.com,布布扣
<html>
       <head>
              <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
              <title>Text Demo</title>
              <style type="text/css">
              h1{
                     color:white;
                     background-color:boue;
                     }
              </style>
       </head>
       <body>
              <h1>This is a line of Text.</h1>
              <h1>This is another line of Text.</h1>
       </body>
       </html>
bubuko.com,布布扣

导入式:将一个独立的css文件导入HTML文件中

<style type="text/css">
     @import"mystyle.css";
</style>

链接式:将一个独立的css文件导入HTML文件中
<link href="mystyle.css" rel="stylesheet" type="text/css" /> 

CSS 入门

原文:http://www.cnblogs.com/dw729/p/3540912.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!