how to link css file from outside web application - css

Simple as title says, how do I include a css file that is found two parent folders up from the actual web application itself?
I have tried adding the file as a link to the web project and then referencing it like that and it dose not work

<link rel="stylesheet" href="../../mystyle.css" /> would literally move up two folders on your server. You may be better off with using the full path: <linke rel="stylesheet" href="/folder1/folder2/mystyle.css" /> - which all assumes that the path you need to get to is accessible to the web server.

Since the page comes from the server I would read the physical file and stuff that onto the page as part of the server script such as:
<style>
<?= css_file_content ?>
</style>
If in a parent folder, it may be outside the hosted path making it inaccessible to the client. But it is not inaccessible to the server-side script.

Visit: http://www.w3schools.com/css/css_howto.asp
You can add inline css if external doesn't work

Related

Apps Script External Stylesheet

I am trying to use a single HTML stylesheet that I've created between multiple apps script web app projects. I have the HTML stylesheet hosted on an external site but cannot figure out the code to include that external stylesheet into my apps script projects.
I've currently got it working with the following code in my Index.html file:
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
<?!= include('stylesheet') ?>
The include function calls:
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename)
.getContent();
}
And my stylesheet is a separate HTML file in my Apps Script.
This all works well, but I'd like to have a central repository elsewhere (I've read that I cannot link to an Apps Script file in another project) for my stylesheet so that whatever changes I make will update to all of my Apps Script projects automatically.
To do this, I've uploaded my stylesheet.html to a website and have taken the link that points to the file (i.e. http://www.test.com/stylesheet.html) and tried to do the following without success:
<link rel="stylesheet" href="http://www.test.com/stylesheet.html">
I've placed this in the head element of my Index.html file, and I also tried it above the head element. Neither worked.
I've also tried to just use the include function that worked as mentioned above and modify my stylesheet.html to be blank except for:
<link rel="stylesheet" href="http://www.test.com/stylesheet.html">
None of this seems to work, wondering if anyone else has any thoughts on how this might be possible.
Host CSS file in Google Drive
Create a .css stylesheet file and host it on Google Drive.
Change the uploaded file permissions to publish it on the Web.
Now copy the published file ID and use it to build the following URL:
https://drive.google.com/uc?export=view&id=FILE-ID-GOES-HERE
Now include the generated URL to your HTML page using the <link/> tag in this way:
<link rel="stylesheet" href="google_drive_link_goes_here">
Reference
Host CSS or JS file on Google Drive

Pulling CSS and JS from base folder

I have an index file that's store on my server under a public_html folder so it can be accessed publicly.
That address is http://example.com/randomlocation/anotherlocation/index.html
on the server that would look like public_html/randomlocation/anotherlocation/index.html
The problem however is that my css, js, and img files to display the page and run it are located on another level outside of the public html section and I'm having trouble specifying the relative or base path to get there, which would be something like:
home/site/folder/randomfolder/anotherfolder/location/styles.css
For Example:
<link rel="stylesheet" href="http://example.com/randomfolder/another folder/assets/css/emojione.min.css"/>
<link rel="stylesheet" href="/home/examplesite/folder/folder/folder/folder/assets/css/styles.css" />
Doesn't seem to work. I've tried all variations of "/" relative paths and can't figure out what I'm missing to be able to pull those files.
Generally when a server has a public_html folder, the server is configured so that only files inside that folder will be accessible publicly via the web. (This way, you can have things like server configs and private files outside of public_html and people won't be able to get to them by just putting the url in their browser.)
In other words, you should move your css/js/images into public_html. You can put them in subdirectories to stay organized, but they should all be under public_html somewhere.
That is purposely not allowed as it would pose a huge security problem on the server. Take a look at this SO question for a possible work around.
php link to image file outside default web directory

ZF2 How To Include google-site-verification <meta> Tag In Twig View

I am trying to add
<meta name="google-site-verification" content="WcGeoFJE8eKgXlxMoHRDpJz1bpPFMGh25PK8M-eDlAw" />
to the section within my layout.twig . I've saved the file and uploaded it to the development version of the web site. But this HTML isn't being included.
All the other entries within the section are Twig codes. Not HTML. I am unsure if I have a cache issue and the revised version of my layout.twig isn't being loaded or if there is some Twig code I should be using for this tag?
Instead of modify the code of your application, I suggest you to proceed to the site verification with the Google file HTML verification procedure.
Simply add the Google files in the web root folder of the project, as example:
./web/googlec1f59ff86d15c795.html
And commit with your source file. In this manner the deploy procedure don't remove your files.
Another good practice, as suggested by # Pazi ツ is to act with the DNS configuration (this require you can manage the DNS site configuration).
Hope this help

IIS CustErr CSS Question

I'm trying to style the custom error pages in IIS7 with a linked CSS style sheet.
This works.
<html><head><title>404 - File or directory not found.</title>
<LINK href="http://stage.mysite.com/custErr/css/style.css" rel="stylesheet" type="text/css">
</head><body>Page Not Found</body></html>
I've created a virtual directory in mysite called custErr that contains the css and images needed.
But to make it easier to deploy I'd like to have it relative like this...
<html><head><title>404 - File or directory not found.</title>
<LINK href="../css/style.css" rel="stylesheet" type="text/css">
</head><body>Page Not Found</body></html>
After trying this I find that relative paths don't seem to work. In fact a style sheet in the c:\inetpub\custerr\en-US folder doesn't work either.
Where are these pages being served from?
Is there an easier way of doing this?
So I don't have to modify each and every absolute path for each environment?
I know this is a late reply but the reason why the relative paths don't work (I think) is because if you hosted a site such as www.myfavouritephotos.com and on visiting a directory on that site such as www.myfavouritephotos.com/images/ which is a directory in your website that doesn't have a default document like Default.aspx or whatever your site is set up as serving as a default page, IIS would return a HTTP Response of 404 for not finding a page to serve up or a 403 response because the user may not have the necessary rights to view the content of the directory under that url.
IIS by default would serve either the 404.htm or 403.htm file from within the c:\inetpub\custerr\en-US directory by default but when you replaced it with a custom htm file that replaces 404.htm, the relative path to the stylesheet you reference from that htm file would make a request at what the original url made to the server was so www.myfavouritephotos.com/images/(../css/style.css) which would result in an incorrect relative path so it may be able to be avoided by using a reference to a stylesheet with www.myfavouritephotos.com/css/style.css

Relative urls for images and js files in MVC application - diff behaviour on local and production server

I have an MVC web application, the urls like following in my views\ folder:
<img src="../../Images/Delete.png"/>
are working on my localhost, but when I deployed the application on production server, they stopped working and when I use single ".." instead of double "../.." , they start working on production server.
Why is this happening ?
This is happening because you probably have a virtual directory in production server and not on localhost. So always use URL helpers when dealing with urls and never hardcode them as you did in your example:
<img src="<%= Url.Content("~/Images/Delete.png") %>" />
You could use relative paths only inside CSS files (for background images for example). Inside CSS files paths are relative to the location of the CSS, but the inclusion of the CSS itself should be done using helpers of course:
<link href="<%= Url.Content("~/Content/Site.css") %>" rel="stylesheet" type="text/css" />
The relative path to the images directory must be different on the production server.
You need to make sure that on your development server the directory layout is the same as on the production server.

Resources