Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jan Egil Kristiansen 37 posts 160 karma points
    May 29, 2015 @ 13:09
    Jan Egil Kristiansen
    0

    Tilde (~) does not work in CSS URL?

    I have the following CSS code in my style sheet:
    background-image:url("~/media/1003/kappe-kort.gif")

    But in the generated style sheet sent to the server, the tilde is still there in literal form, cuasing the browser to look for /css/~/media/1003/kappe-kort.gif rather than /media/1003/kappe-kort.gif.

    Using
    background-image:url("/media/1003/kappe-kort.gif")
    without the tilde works fine. But isn't the tilde version supposed to be more robust?

    Umbraco 7.1.8
    ASP.NET MVC 4
    Windows 7 pro SP1
    IIS 7

     

  • Chris Day 34 posts 107 karma points c-trib
    May 29, 2015 @ 15:44
    Chris Day
    0

    The ~/ root is a server side feature of .NET. In the HTML output from the server it will be replaced with the root application file path in HTML.

    It is deemed more robust because it means your application could still work in a sub folder or root directory if required.

    CSS is not run at the server side so you can't actually use the ~ in .css files. Stick with / and amend your CSS if the application is ever moved to a sub folder.

Please Sign in or register to post replies

Write your reply to:

Draft