zoukankan      html  css  js  c++  java
  • css中url的路径含义及使用

    http://www.jb51.net/css/37554.html

    在CSS中有用url语法来指定background-image或是其他引用文件中,如:

    复制代码
    代码如下:

    .mainheader{
    height:52px;
    background-image:url(../images/mainheader_top_bj.gif);
    background-repeat: repeat-x;
    background-position: top;
    }


    1.background-image一类:
    实际应用时,经常把css写入样式文件中,并放入专门的目录,把图片放入专门图片目录中,而实际使用的aspx文件在另一个目录,假设有这样一个实际应用目录:
    ----root
    ----images
    --mainheader_top_bj.gif
    ----css
    --a1.css
    ----ff.aspx
    其中,ff.aspx引用到a1.css,而a1.css中有.mainheader,如文章开头那样的url定义,想使用images中的mainheader_top_bj.gif的图片.
    这个url的路径应该以ff.aspx为准,还是以a1.css为准?
    经测试,发现该路径以a1.css(也即CSS文件)为准,不论是HTML文件使用还是在asp.net网站中,都是如此.
    2.behavior一类
    IE使用的 behavior: url(xxx/xxxxx.htc)来做HTML组件,这时,url里指定的htc文件路径,则是相对HTML所在的目录来的了,如下目录:
    ----root
    ----images
    --mainheader_top_bj.gif
    --iepngfix.htc
    ----css
    --a1.css
    ----pub1
    --frm1.aspx
    ----ff.aspx
    则ff.aspx使用的a1.css文件中要指定behavior,则要如下:

    复制代码
    代码如下:

    behavior: url(images/iepngfix.htc)


    当然,这个用法就比较死板了,这样一来,这个css文件就只能root目录下的aspx和html文件使用了,如果pub1目录下的frm1.aspx想用这个css,那上面的那个htc目录就不对了,而应该变为:

    复制代码
    代码如下:

    behavior: url(../images/iepngfix.htc)


    当然,这样用,还不如直接在每个aspx文件里指定这个htc,而不是把这个htc式子放入css中;如果能定下网站的相对根(/)的相对路径,也可以写成(假设iepngfix.htc固定放在网站根下的/images目录中):

    复制代码
    代码如下:

    behavior: url(/images/iepngfix.htc)
  • 相关阅读:
    CSS中position小解
    position
    mac默认安装postgresql, 如何让postgresql可以远程访问
    The data directory was initialized by PostgreSQL version 9.6, which is not compatible with this version 10.0.
    active admin gem error
    psql 无法添加超级用户
    ubuntu 15.04 安装Balsamiq Mockups 3
    Rails html 写public里图片的路径
    rails c 历史命令
    undefined local variable or method `per' for []:ActiveRecord::Relation
  • 原文地址:https://www.cnblogs.com/jingzhishen/p/3430350.html
Copyright © 2011-2022 走看看