在asp.net.mvc,什么是引用CSS内的图像的正确方法 [英] in asp.net.mvc, what is the correct way to reference images inside of css

查看:165
本文介绍了在asp.net.mvc,什么是引用CSS内的图像的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我检讨一个网站,我看到了很多不同的约定上回放照片如何在asp.net MVC的网站CSS参考。

I am reviewing a site and i see a lot of different conventions on reviewing how images are reference in CSS on a asp.net-mvc site.

包括:


  1. 完整路径

.ddTitle span.arrow {
    background: url('/content/images/dd_arrow.gif') no-repeat 0 0;
}


  • 相对位置与其中的CSS位于:

    #cluetip-waitimage {
        background-image: url(jQueryUI/images/ui-anim_basic_16x16.gif);  
    }
    


  • 相对与.​​.

    #cluetip-waitimage {
        background-image: url(../../jQueryUI/images/ui-anim_basic_16x16.gif);  
    }
    


  • 在asp.net MVC的,具有路由等。 。是个正确的和别人错或者这只是preference或约定?假设该网站可能会坐在与其他网站共享环境。

    In asp.net-mvc, with routing, etc . .is one correct and the others wrong or is this just preference or convention? Assume that this site might sit on a shared environment with other sites.

    推荐答案

    您第一个选项是非常好的,如果你的应用程序总是要在根文件夹中的网站(或至少您的图像都将要在根文件夹)。如果您有可能在不同情况下不同的路径(就像在开发或测试共享站点),那么这是行不通的。

    Your first option is perfectly fine if your application is always going to be in the root folder for the website (or at least your images are all going to be in the root folder). If you might have a different path in different situations (like having a shared site on development or testing), then this doesn't work.

    第二个和第三个选项基本上是相同的事情。哪一个被使用完全取决于其中图像位于相对于CSS文件。我个人认为,第二个看起来比较清爽,所以我尽量把我的CSS文件中引用的任何图像相对于那里的CSS所在的文件夹结构。然而,有些人preFER把所有的图像在一个地方(甚至是混合内容的图像与网站的铬的图像),因此可能需要使用相对路径与 ../ 为了实现这一目标。

    The second and third options are basically the same thing. Which one is used is completely dependent upon where the images are located in relation to the CSS file. I personally believe that the second looks cleaner, so I try to put any images referenced by my CSS files in a folder structure relative to where the CSS is located. However, some people prefer to keep all images in one place (even mixing content images with site "chrome" images) and as such may need to use relative pathing with ../ in order to accomplish this.

    这篇关于在asp.net.mvc,什么是引用CSS内的图像的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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