PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

html中怎么插入CSS?css插入html的四种方法介绍(附代码)

不言
不言 原创
2018-08-18 14:47:18 8130浏览

本篇文章给大家带来的内容是关于html中怎么插入CSS?css插入html的四种方法介绍(附代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

1.注释:
(1).HTML的注释:
(2).CSS的注释:/* *

2.HTML中插入CSS(层叠样式表)的方法
(1).行内样式 (在标签后面直接写样式)

<!doctype html>
<html>
<head>
   <meta charset="utf-8">
   <title>行内样式</title>
   </head>
   <body>
    <p style="font-famliy:宋体; text-align:center;font-style:italic; text-transform:uppercase; font-size:22px;  text-decoration:underline; font-weight:bold; letter-spacing:13px">html中插入css样式的方法:</br>1 行内样式;2 内部样式; <br/>3 外部样式; 4 导入样式;</p>
    </body>
    </html>

(2)嵌入式(将样式和html语言分开写)

<!doctype html><html><head>
   <meta charset="utf-8">
   <title>行内样式</title>
   <style type="text/css">
   p{    text-decoration:underline;    text-align:center;    font-size:26px;    font-family:宋体;    font-weight:bolder;    text-transform:lowercase;    letter-spacing:4px;    color:pink;    background-color:green;   }

   </style></head><body>
    <p >HTML中插入CSS样式的方法:</br>
        1 行内样式;2 内部样式; <br/>
        3 外部样式; 4 导入样式;    </p></body></html>

3.外部样式(链接式:将CSS和HTML分开写)!!!!最常用
first.html

<!doctype html><html><head>
   <meta charset="utf-8">
   <title>行内样式</title>
   <link href="first.css" type="text/css" rel="stylesheet"></head><body>
    <p >HTML中插入CSS样式的方法:</br>
        1 行内样式;2 内部样式; <br/>
        3 外部样式; 4 导入样式;    </p></body></html>

first.css

p{    text-decoration:underline;/*加下划线*/
    text-transform:lowercase;/*大写字母全部小写*/
    text-align:center;/*居中*/
    font-size:23px;/*字体大小*/
    font-family:黑体;/*设置字体*/
    font-style:italic;/*设置字倾斜*/
    text-indent:3px;/*设置首行缩进*/
    color:red;/*设置字体颜色*/
    background-color:#ddd;/*设置背景颜色*/
    letter-spacing:4px;}

4.导入式
first.html

<!doctype html><html><head>
   <meta charset="utf-8">
   <title>行内样式</title>

   <style type="text/css">
    @import url(first.css);   </style></head><body>
    <p >HTML中插入CSS样式的方法:</br>
        1 行内样式;2 内部样式; <br/>
        3 外部样式; 4 导入样式;    </p></body></html>

first.css

p{    text-decoration:underline;/*加下划线*/
    text-transform:lowercase;/*大写字母全部小写*/
    text-align:center;/*居中*/
    font-size:33px;/*字体大小*/
    font-family:黑体;/*设置字体*/
    font-style:italic;/*设置字倾斜*/
    text-indent:3px;/*设置首行缩进*/
    color:red;/*设置字体颜色*/
    background-color:#ddd;/*设置背景颜色*/
    letter-spacing:4px;}

相关推荐:

JavaScript动态插入CSS的方法_javascript技巧

HTML中引入CSS的方法

以上就是html中怎么插入CSS?css插入html的四种方法介绍(附代码)的详细内容,更多请关注php中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。