How to use external style sheet in webmatrix - css

I have a problem with my webmatrix in using an external style sheet,the page still loading and nothing appear,but when I put the css I used in a style tag inside the head tag the problem is solved , but i need to put them in an external file ... how ?
why I faced that problem ?

There isn't anything you do differently in WebMatrix for this (except that you may want to prepend the path to your file with a tilde (~) which has the effect of telling the server-side code to make an absolute path out of a relative one in ASP.Net Web-Pages [not sure about Web-Forms or MVC]).
You just do this:
In your HTML Page (in the <head> section):
<link href="~/someDirectory/someCSSFile.css" rel="Stylesheet" type="text/css" />
Then just make sure the css path and file name are correct, and you're good to go.

Related

adding website thumbnail to facebook through css (og:image)

I have standard html files with their own style, and use a common css file for different fonts only. I need to put the FB website thumbnail to all the files through that css.
Is it possible to add the following to the css or .js files? (as there are thousands of html files):
<meta property="og:image" content="http://websitename/image.jpg">
You'll need to add that snippet to the html itself, not the css. Meta tags go into the head of your webpage (between the <head></head> tags). There's no way to insert html into a page via a css file.
OpenGraph is some standard - even if you did put it inside your CSS - nobody would know it's there - so no, it can't be done with CSS.
If some website would process the javascript (but facebook hardly would) you could get lucky but the chances are really low so it is not reliable.
However I suggest you to write a little e.g. PHP skript that would run through all the .html / .htm files and would rewrite <head> with <head> <meta property="og:image" content="http://websitename/image.jpg">
But I suggest that instead of adding only html, it would be much better if you would add an include script that would contain further cross-files changes. So next time you would need to add something to <head> in all your files you would just add it inside your e.g. my_include.php
EDIT:
I would also recommend you to look at the facebook's developer tool that tells you exactly what it sees when it visits your site: https://developers.facebook.com/tools/debug/og/echo?q=YOURSITEURL

Including CSS in MasterPages

I am new to the domain. I want to include a CSS file in my master pages,but it is not working can anyone try to help me out of this problem..
I give the link to the CSS externally as
<link href="Stylesheet1.css" rel="Stylesheet1" type="text/css" />
Is there any necessity to include CSS classes in master page if so how and where I have to include?
Try:
<link href="~/Stylesheet1.css" rel="Stylesheet1" type="text/css" />
Tilde (~) represent root directory.
If this doesn't work, if you can show us your directory structure, and look at the rendered source we can help more.
You can of course not use the Tilde (~) on tags that are not run server-side, what you have to do is something like this:
<link href="<%= ResolveClientUrl("~/Stylesheet1.css")%>" rel="stylesheet" type="text/css" />
Or just do a method that gives you back a full link-tag.
There's nothing wrong with the syntax of your <link> tag. The problem is likely to be caused by the fact that your CSS file isn't located at the URL you're attempting to get it from.
The href attribute in your markup specifies a file called Stylesheet1.css in the same folder as your master page. If its not you should specify the location of the stylesheet using standard, virtual path or move the stylesheet to the same folder as your masterpage.
More info.
http://w3schools.com/css/css_howto.asp

Why the CSS style is not applied in webpages within subdirectories?

In the root of my domain i have the CSS file style.css and the masterpage file site.master.
The link to the CSS file within the site.master is
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
The problem is that webpages contained within subdirectories do not inherit the CSS file.
What am i doing wrong here?
If i copy the style.css file to the subdirectories everything works like a charm...
UPDATE: If i change the path to /style.css or to ~/style.css the style is Not applied also to the webpages within the root folder.
MasterPages use the containing page for the path.
change your css tag to be a server control and use the "~" root symbol.
<link id="lnkStyle" runat="server" href="~/style.css"
rel="stylesheet" type="text/css" />
You need to specify the path as /style.css.
Well the obvious question is, does the other pages inherit the correct masterpage, namely the one with your css link?
ie.
<%# Page Language="C#" MasterPageFile="~/MasterPage.master"...
also perhaps '/' before file name would help
If you're including that link tag in your master page, the HTML being output by the content pages in subdirectories contains a link to "style.css", which the browser looks for in that directory.
If you're developing in ASP.NET, you should be placing your CSS files in themes, which will take care of this problem. If you really don't want to do that for some reason, make the URL to the stylesheet an application-relative path ("~/style.css") and make the link tag executed on the server; I believe that that will resolve the application path and generate an absolute URL.
Try this:
<link href="<%: Url.Content("~/style.css") %> rel="stylesheet" type="text/css" media="screen" />
It will make the path relative to your hostname, giving the correct path to your pages in the subdirectories. Right now, just linking style.css gives it the folder relative path, so its looking inside of the same folder your page is in, instead of where you intended. Hope that helps. You could also re-write your link with a preceding forward slash, like "/style.css" and that should also do the trick.

Problems referring a css from an XHTML

In my JSF Application (My faces 1.2.3) , I am referring to a css file as
<link href="css/nav.css" type="text/css" rel="stylesheet" />,
This worked when the rendered HTML is accessed as an HTML file using the browser but not inside my customized servlet container.
It wasn't referring correctly, eventhough the relative path was correct. Then I tried with
<link href="../css/nav.css" type="text/css" rel="stylesheet" />
It worked in a browser and did not in some other browsers.
I was told that I should use facelets.DEVELOPMENT" = true to make it work , It worked in Dev Env and it did not in Test Env (There will be some inherited properties!!! and not everything will be used from my application)
I have some knowledge on these accompanying technologies but not an expert. Wondering whats the issue and where ? - Servlet Container , XHTML , Facelets , JSF Impl ?
Any Idea - What could be the problem?
A relative <link> URL is relative to the request URL as it is on the client side, in the webbrowser's address bar (the webbrowser is namely the one responsible for loading the CSS files), it is not relative to the folder structure as it is on the server side.
So if the request URL is for example http://example.com/context/page.jsf, then the CSS which is referenced by href="css/nav.css" will be loaded by http://example.com/context/css/nav.css and the CSS referenced by href="../css/nav.css" by http://example.com/css/nav.css.
If you still stucks with this, then you need to post both the absolute URL with which you can request the page in question successfuly and the CSS file itself. This way we can explain you which relative URL to the CSS file you should be using for the page in question.
Probably the problem is that your application is not absolute to the request url
Lets assume that you access your application via:
http://localhost/my-app/
And now when you try to load a resource as you described above
<link href="css/nav.css" type="text/css" rel="stylesheet" />
It will be loaded by
http://localhost/css/nav.css
I would suggest using the context path property when referring resources.
<link rel="stylesheet" type="text/css" href="#{request.contextPath}/css/style.css"/>
One potential solution here would be to use a root relative path, something like.
/MyCSSFolder/myfile.css
In most cases this can resolve the issues.

CSS and images on Master Page

I have this quite popular problem, but have failed to find a solution that works.
Basicly, I am using a Master Page (/Masterpages/Default.master), that includes
<link href="../css/style.css" rel="stylesheet" type="text/css />
And it also includes some images with the same relative linking.
But when I apply the Master Page to content pages (in diffrent folderlevels) the css formating and images is lost.
Is there anyway to dynamicaly solve the folderlevel links to css and images to all content pages using the masterpage?
Thanks in advance
UPDATE:
There is an additional problem. It's tricky to get the output to render correctly in both the browser and in design view in Visual Studio.
I got it to work by using the asp:image solution for the images in the masterpage and by double linking the css in the masterpage, one to make it render in VS and one to make it render correctly browsing the site.
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<link href="<%=ResolveUrl("~/css/style.css")%>" rel="stylesheet" type="text/css" />
best to use:
<link href="<%=ResolveUrl("~/css/style.css") %>" rel="stylesheet" type="text/css />
since this will cope with iis application roots unlike:
<link href="/css/style.css" rel="stylesheet" type="text/css />
You can make your link runat="server" and use tilde mapping to make the CSS path relative to the site root.
<link runat="server" id="siteStyle"
href="~/css/style.css"
rel="stylesheet"
type="text/css" />
The images referenced in the CSS should be relative to the location of the CSS file and should resolve normally once the CSS file itself is included properly. For images in tags on the page, you would need to use the ASP:Image control and, again, use the tilde mapping for a path relative to the root.
Fairly sure this will work
<link href="/css/style.css" rel="stylesheet" type="text/css />
/ takes you to the root of your site
You can use the tilde to get the link to work from anywhere. This will work in Images as well.
<link runat="server" href="~/css/style.css" rel="stylesheet" type="text/css />
Images in CSS are relative to the file they are referenced from.
(An exception from this is the "filter" rule in Internet Explorer which is used for PNG fixes. The images in this case are relative to the HTML document.)
Yes, the problem is that the materpage is using a relative url to load the CSS:
"../css/style.css"
you need to change this to the site root (depending on the location of your css files) something like:
"/css/style.css"
than all the various folder levels can use the same url.
Actually, master pages will rebase css files for you automatically, without you having to add runat="server". Be sure that your css file is located one directory down in the folder you specified.
You can use an absolute path to the css file, but visual studio doesn't seem to render the styles in design view when you do this. Also, sometime you won't know if you're going to be running in a virtual directory, so it's not always ideal to use the absolute path.
Also, use relative links to your image assests from the css file itself - which will work irrespective of how you link to your stylesheet.
You might also be interested in looking into themes and skins.
ASP.NET Themes and Skins Overview

Resources