How to specify a standard path (location) for stylesheets - css

Is there a way to specify a standard path for stylesheets (analogous to the "include_path" directive in the php.ini file that specifies the location of PHP includes files) such that you only need to specify the unqualified stylesheet filename in the href value of the link element? Example, just be able to write:
<link rel="stylesheet" href="main.css" />
in all files, regardless of their location on the website, without having to worry about where the main.css file is located?
Thank you

Start your path with a / and it will be interpreted relative to the root of your website and will work on any file regardless of its location:
<link rel="stylesheet" href="/main.css" />
or if main.css is not in root:
<link rel="stylesheet" href="/some_folder/main.css" />

Use the HTML-base-tag:
<base href="http://your.domain/and/path/here/" />
Now, all your links will start at that position, even URL's inside a <LINK>.

Related

datatables.min.css doesn't work from local project

I have a ASP.NET MVC project which uses JQuery Datatables to show a table.
The problem: the css stylesheet isn't applied when links to local css file. I've tried the following:
<link rel="stylesheet" type="text/css" href="~/Content/datatables.min.css" />
<link rel="stylesheet" type="text/css" href="../Content/datatables.min.css" />
<link rel="stylesheet" type="text/css" href="/Content/datatables.min.css" />
<link rel="stylesheet" type="text/css" href="Content/datatables.min.css" />
But this one (at the same place of my HTML) is working:
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.16/datatables.min.css" />
Even current sorting column highlight from this css doesn't work!
Of course, the CSS file exists in my project's Content folder, and its contents is totally the same, because I even try to copy the file from https://cdn.datatables.net/v/dt/dt-1.10.16/datatables.min.css and put it in project's Content folder.
So, the question is why doesn't the first HTML link snippet work?
Maybe, a bug in the MVC (it's up to date)?
jQuery DataTables distribution includes CSS, JS and image files (in the images folder).
Use Download builder, select Download tab and download all required files.
Also you should not use ~ in your URL. Most likely that is the reason why CSS is not applied. Use absolute URL /Content/datatables.min.css or relative URL Content/datatables.min.css instead.

How to set absolute css path as in jsp

Why we need absolute path and how I can set absolute path for css files which are included in my project.I am using spring mvc.The css files are in different folder which is inside web-inf folder in tomcat/webapp.Now i am using something like below
<link href="AllCSS/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
what should i need to do exactly?
Absolute in a webapp assumes starting from the webapp root context, in your case if /Allcss is a directory under root, absolute would mean
<link href="${pageContext.request.contextPath}/Allcss/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
if its a webapp context than
<link href="${pageContext.request.contextPath}/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>

Linking to stylesheet in root directory

I am having a major issue trying to link to a stylesheet which is my root directory. I am connecting to it from a HTML file which is in a subdirectory of the root directory.
I would think this code would work (seeing as / means root directory)
<link type="text/css" rel="stylesheet" href="/style.css" />
However, it does not. Because the subdirectory is also only one folder down from the root directory, I also tried:
<link type="text/css" rel="stylesheet" href="../style.css" />
this also does not work.
Your first code line should work as "/" really means root :
<link type="text/css" rel="stylesheet" href="/style.css" />
This will find the file https://MY_DOMAIN/style.css
Are you sure that your file style.css is at the root of your project and not in another folder ?
Also you can try
<style>
#import url('/style.css');
</style>
I finally found a solution that works. For whatever reason, I could not link back to the root directory. I am still completely baffled about that, however, I did find a way to make it work.
I did it with this code:
<head>
<link type="text/css" rel="stylesheet" href="http://engagearcade.com/style.css" />
</head>

Meteor how to serve multiple css for different media types?

I would like to have my Meteor app serve multiple css pages for various media types. For example:
<link rel="stylesheet" type="text/css" media="screen" href="screen.css" />
<link rel="stylesheet" type="text/css" media="print" href="print.css" />
<link rel="stylesheet" type="text/css" media="handheld" href="handheld.css" />
How would I do this?
/packages/meteor/package.js
defined that .css files should be bundled.
However, taking a close look at docs.meteor.com, we can find this information:
CSS files work just the same: the client will get a bundle with all the CSS in your tree (excluding the server and public subdirectories).
That last part is the interesting bit, if you place your CSS files in /public they will not get bundled together. Instead app/lib/bundler.js does the following around line 517:
files.cp_r(path.join(project_dir, 'public'),
path.join(build_path, 'static'), {ignore: ignore_files});
And server side, any files that are unresolved will also be checked in build/static, which means that when you put screen.css in /public you can keep using screen.css on the client.

Linking to a parent stylesheet - ../?

I am having an issue with style sheets in a higher director. Here is the example;
I have index.php and style.css in the example.com home folder. Then, I have example.com/contact with index.php in there. The index.php in the contact folder, points to the stylesheet at example.com home folder.
The issue I am having is say I want a div to be displayed as a block and be a hyperlink. The style.css works fine at example.com/index.php, but if you click the link while in the /contact folder, it will try to access /contact/index.php instead of just /index.php.
Is there a way to fix this?
Thanks!
I assume you mean you are having problems with the CSS path in different directories of your site?
You can link to the stylesheet absolutely, or by using base href ~
<link rel="stylesheet" type="text/css" href="http://mysite.com/style.css" />
or
<link rel="stylesheet" type="text/css" href="/style.css" />
or
<base href="http://site.com/" />
<link rel="stylesheet" type="text/css" href="style.css" />
Rather than using ../ (which I believe goes up 1 directory) use just /, which will go to root directory (e.g example.com/):
<link rel="stylesheet" type="text/css" href="/style.css" />

Resources