CSS根目录 [英] CSS root directory

查看:671
本文介绍了CSS根目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含背景图片的样式表。

  background:url(../ Images / myImage.png ); 

问题是,来自不同目录的页面使用此css!



我的CSS文件位于CSS文件夹中,图像文件夹中的图像和我的html页面位于许多不同的文件夹中,具体取决于网站的内容和意义。



所有我的页面继承这个css,因为它是MAIN主题。



上面的例子中使用的路径是一个相对路径。显然,这个路径只适用于一些页面。所有我需要的是链接在css从ROOT文件夹中的图像。因此,无论文件在文件夹结构中的什么位置,每个路径都是正确的!



我试过:

 〜/ Images / myImage.png 
./Images/myImage.png
/Images/myImage.png
图片/ myImages.png

我不认为根文件夹选择器存在...但我希望它:/

解决方案

  /Images/myImage.png 

这必须在您的网域/子网域的根目录中。



http://website.to/Images/myImage.png



它会工作




  • ul>
  • yourimage.png


  • 样式

    • style.css




  • style.css:

      body {
    background:url(../ images / yourimage.png);
    }


    I have a style sheet where I include background images.

    background: url(../Images/myImage.png);
    

    problem is, pages from different directories use this css!

    My CSS files are in a CSS folder, images in an Image folder, and my html pages are in many different folders depending on their content and meaning to the website.

    All my pages inherit this css as it is the MAIN theme.

    The path used in the above example is a relative path. And obviously, this path only works for some of the pages. ALL i need is to link the images in the css from the ROOT folder. Therefore every path is correct no matter where the file is in the folder structure!

    I have tried:

    ~/Images/myImage.png
    ./Images/myImage.png
    /Images/myImage.png
    Images/myImages.png
    

    I don't think a root folder selector exists... but I hope it does :/

    解决方案

    /Images/myImage.png
    

    this has to be in root of your domain/subdomain

    http://website.to/Images/myImage.png

    and it will work

    However, I think it would work like this, too

    • images
      • yourimage.png
    • styles
      • style.css

    style.css:

    body{
        background: url(../images/yourimage.png);
    }
    

    这篇关于CSS根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆