Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include all css kept in a directory?

Tags:

html

css

Is it possible to include multiple css at once in html? Or to be precise, is it possible to include all css placed in a directory, in one go?
like at present what we do is:-

<link type="text/css" rel="stylesheet" href="./tabs_css/navigation.css"> 

I need something like:-

<link type="text/css" rel="stylesheet" href="./tabs_css/*.css"> 

Is it possible? Or is there any alternative of this?

like image 267
Rakesh Juyal Avatar asked Feb 24 '10 14:02

Rakesh Juyal


People also ask

How do I put all CSS in one file?

In your HTML header, you have two options: 1) place the HTML with CSS directly into your HTML header or 2) put the Standalone CSS into mycssfile. css and include that into your HTML header as <link href="mycssfile. css" /> .

How do I include all CSS files in HTML?

CSS can be added to HTML documents in 3 ways: Inline - by using the style attribute inside HTML elements. Internal - by using a <style> element in the <head> section. External - by using a <link> element to link to an external CSS file.

How do I reference a CSS file in the same folder?

If both HTML and CSS files are in the same folder, enter only the file name. Otherwise, include the folder name in which you store the CSS file. media – describes the type of media the CSS styles are optimized for. In this example, we put screen as the attribute value to imply its use for computer screens.


2 Answers

You could create a master stylesheet that you include in every page, and within that css file you can use @import to include the others.

This doesn't solve the problem of having to manually include each individual css file, but at least it encapsulates it within the master stylesheet so you don't have to repeat all of the references in every html file. If you add additional css files you will only need to add a reference in the master css and all pages will get access to it.

Example HTML CSS Reference:

<link href="master.css" type="text/css" /> 

Example Master CSS (master.css):

@import url(style1.css); @import url(style2.css); @import url(style3.css); 

Read more about when to use @import and its compatibility with older browsers.

like image 123
Abram Simon Avatar answered Oct 10 '22 19:10

Abram Simon


You'd need to do this serverside. If you're using PHP, have a look at glob.

For example:

foreach (glob("path/to/css/*.css") as $css) {     echo "<link type='text/css' rel='stylesheet' href='$css'>\n"; } 
like image 45
Skilldrick Avatar answered Oct 10 '22 19:10

Skilldrick