css三种样式

一。行内样式
(很少使用)

     <h1>静夜思</h1>
    <p>床前明月光,</p>
    <p style="color: red;">疑是地上霜。</p>
    <p style="color: #0000FF;font-size: 1rem;">举头望明月,</p>
    <p>低头思故乡。</p>

二。内嵌样式
(常用于中小型网页)

  <head>
    <meta charset="utf-8">
    <title>
    </title>
    <style type="text/css">
        h1{color: red;}
        #aa{color: #0000FF;}
        .bb{color: #00FF00;}
    </style>
</head>
<body>
    <h1>静夜思</h1>
    <p id="aa">床前明月光,</p>
    <p class="bb">疑是地上霜。</p>
    <p>举头望明月,</p>
    <p>低头思故乡。</p>
</body>

三。外部链接
(常用于大型网页)
新建.css文件,在css文件中不需要写<style>
连接方式1<link rel="stylesheet" type="text/css" href=".css"/>
连接方式2<style type="text/css">@import url("
.css");</style>

样式表中:

    .red{color: red;}
  #green{color: green;}

连接方式1

<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="css/样式表.css"/>
</head>
<body>
    <h1>静夜思</h1>
    <p class="red">床前明月光,</p>
    <p>疑是地上霜。</p>
    <p id="green">举头望明月,</p>
    <p>低头思故乡。</p>
</body>

连接方式2

<head>
    <meta charset="utf-8">
    <title></title>
    <style type="text/css">
          @import url("样式表.css");
    </style>
</head>
<body>
    <h1>静夜思</h1>
    <p class="red">床前明月光,</p>
    <p>疑是地上霜。</p>
    <p id="green">举头望明月,</p>
    <p>低头思故乡。</p>
</body>

猜你喜欢

转载自blog.51cto.com/14648170/2462729