一个css文件和html文件是怎么建立连接的?

2025-03-18 11:01:14
推荐回答(4个)
回答1:

一个css文件和html文件是通过动态导入到html页面建议联系的。

比如有一个外部css文件,header.css:

内容如下:

 body {  

            font-family: "黑体";  

            font-size: 12px;  

            color: #000;  

            margin: 0px;  

            text-align:center;  

            margin-left: 20px;  

            margin-top: 50px;  

            margin-right: 20px;  

            margin-bottom: 20px;}

    div#wrap {   

            width:800px;   

            margin:0 auto;   

            border:1px solid #333;  

            background-color:#ccc;  

            text-align:center;  

            background-image:url(images/bg_img04.jpg); }   

          

    div#header {  

            width:780px;  

            border:1px solid #333;  

            font-family: "宋体";  

            font-size: 14px;  

            color: #000;  

            text-align:center;  

            margin-left: 10px;  

            margin-top: 30px;  

            margin-right: 10px;  

            margin-bottom: 5px;}  

           

    div#footer{  

            width:780px;  

            border:1px solid #333;  

            font-family: "宋体";  

            font-size: 12px;  

            color: #000;  

            text-align:center;  

            margin-left: 10px;  

            margin-top: 30px;  

            margin-right: 10px;  

            margin-bottom: 8px; }  

      

      

    div#center{  

            width:780px;  

            border:1px solid #333;  

            font-family: "宋体";  

            font-size: 12px;  

            color: #000;  

            text-align:center;  

            margin:0 auto;   

            margin-left: 10px;  

            margin-top: 10px;  

            margin-right: 10px;  

            margin-bottom: 5px; 

            }  

  

    a {   

        font-size: 14px;   

        color: #000;  

        font-family:"黑体"; }  

      

    a:link {  

        text-decoration: underline;  

        color: #009;}  

      

    a:visited {  

        text-decoration: underline;  

        color: #306;}  

      

    a:hover {  

        text-decoration: none;  

        color: #900;}  

      

    a:active {  

        text-decoration: underline;  

        color: #36C;}  

2、html代码如下:

 

 

 

CSS DIV 样式布局 III  头header   脚 footer  身 center  

   

 

   

  

       

 

         

 

           

 

         

 

            

         

 

           

 

           

 

         

 

           

 

         

 

       

 

               

 

           

 

               

 

                    ···················代码编辑区域······················  

               

 

           

 

   

 

 

 

这样当页面运行后,对应的样式就会加载出来。

运行结果:

回答2:

建立连接方式有几种
一、在head里用
二、在style标签里用@import url(demo.css )

回答3:

在需要建立连接的html文件头部加入此语句即可

回答4:

在HTML的head部分通过link标签引入css样式文件。

href为样式文件地址!