CI框架引入CSS文件的方法是什么?

html-css015

CI框架引入CSS文件的方法是什么?,第1张

1、两种方法,相对路径和绝对路径

2、相对路径是相对网站根目录的路径也就是index.php所在的路径

3、绝对路径可以使用config.php中base_url配置

4、举例:static是根目录下的文件夹,存放静态文件

相对:

<script src="static/js/web.js"></script>

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

绝对:

首先php获取base_url的值

$base_url = $this->config->item('base_url')

//通过参数传递到html页面

$this->load->view('index', array('base_url'=>$base_url))

//页面中使用

<script src="<?php echo $base_url?>static/js/web.js"></script>

<link rel="stylesheet" type="text/css" href="<?php echo $base_url?>static/css/style.css">

CSS position:

static:默认属性,静态定位

relative:相对定位,相对于父元素的定位,需要配合top,left,right,bottom,z-index等属性

absolute:绝对定位,相对于父元素的定位,需要配合top,left,right,bottom,z-index等属性

fixed:固定定位,相对于父元素的定位,需要配合top,left,right,bottom,z-index等属性(IE6不支持)

你看一个例子就明白了。

<!DOCTYPE HTML>

<html lang="zh-cn">

<head>

<meta charset="UTF-8">

<title>CSS POSITION</title>

<style type="text/css">

.wrap{position:relativeheight:800pxz-index:1}

.ps, .pf, .pr, .pa{width:80pxheight:80pxline-height:80pxtext-align:centercolor:#FFFfont-weight:600font-size:18px}

.ps{position:staticbackground-color:silver}

.pf{position:fixedbackground-color:greentop:50%left:50%}

.pr{position:relativebackground-color:redtop:30pxright:-130pxz-index:10}

.pa{position:absolutebackground-color:orangetop:60pxleft:60px}

</style>

</head>

<body>

<div class="wrap">

<div class="ps">static</div>

<div class="pf">fixed</div>

<div class="pr">relative</div>

<div class="pa">absolute</div>

</div>

</body>

</html>