Importing StyleSheets


As your stylesheets become larger and larger it is recommended that you should break it into parts and then import in into the main stylesheet.

For Example, you have a main.css , header.css, footer.css. After creating these separate stylesheets you can import these into the main.css.

main.css

@import url('header.css');
@import url('footer.css');
#content{
font-size:18px;
font-family:sans-serif;
}

footer.css

#footer{
background-color: #eaeaea;
font-family: calibri, sans-serif;
text-align: center;
font-weight: bold;
}

header.css

#header{
font-family: calibri, sans-serif;
font-kerning: auto;
font-size: 32px;
justify-content: flex-start;
}
#tagline{
font-family: calibri, sans-serif;
font-kerning: auto;
font-size: 26px;
justify-content: flex-start;
}

and here is our HTML file,

index.html

<html>
<head>
<title>DL Alpha Demo</title>
<link rel="stylesheet" href="./main.css" />
</head>
<body>
<h1 id="header">DL Alpha 0.764b</h1>
<h2 id="tagline">Tagline should go here</h2>
<div id="content">
Here goes the main content for DL Alpha 0.763b
</div>
<p id="footer">Copyrights 2014 &copy;</p>
</body>
</html>

These are not very large Stylesheet, I just want to demonstrate how to import Stylesheets into another Stylesheet 😊

Note that you must write the @import on the top of css or may be after @charset. If you add comment before these they will not going to work.

You can also specify the media type while importing stylesheet as below.

@import url('header.css'); all
@import url('footer.css'); print
#content{
font-size:18px;
font-family:sans-serif;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s