CSS——结合方式

其实html,css,javascript一般是放在一起学的,html主要用于定制一个页面的框架,早期只有html,没有css,这时候很多页面显示的部分的渲染都是靠html属性来做的,像font中的属性,color,size等,随着之后的发展,html文件中写太多的东西会显得很臃肿,于是为了“解耦合”,CSS就应运而生了,下面就是介绍CSS和HTML的结合方式了,这里主要介绍三种:
1、直接在html标签上加style属性,属性的值填写css代码,所有的标签都有style属性。
举例:将一句话设置为红色;

<html>
<head>
    <title>结合方式1</title>
</head>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html";charset="utf-8">
<body>
    <p style="color:red;">Welcome to CSS World!</p>
</body>
</html>

2、使用head标签中的style标签。设置页面样式。style中填写css代码;
举例:将两句话设置为红色;

<html>
<head>
    <title>结合方式2.html</title>

    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html;charset=utf-8">

    <style type="text/css">
  p{
        color:red;
    }
    </style>

</head> 
<body>
    <p>Welcome to CSS World!</p>
    <p>----Welcome to CSS World----!</p>
</body>
</html>

3、应用外部的一个链接link,同样的在head中添加;这里需要先建立一个css文件,用于link使用;命名为p.css;

p{
    color:red;
}

接着在下面的代码中引用;

<html>
<head>
    <title>结合方式3</title>

    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html;charset=utf-8">

    <link rel="stylesheet" type="text/css" href="p.css">

</head>

<body>
    <p > Welcome to CSS World!</p>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值