Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get my @import stylesheet to override the main stylesheet?

Tags:

css

I imported another stylesheet using @import in the main style sheet file. I would like the changes I have made in the @import stylesheet to override the main style sheet. Is this possible?

like image 784
Kenshi Avatar asked Oct 03 '11 21:10

Kenshi


2 Answers

This solution working perfect for me.

Make copy of your main.css and rename it to style.css. In main.css delete all and past :

@import url("style.css");
@import url("style-override.css");

Thats all.

like image 111
Sayd Imaker Avatar answered Sep 27 '22 16:09

Sayd Imaker


If your goal is to override styles by importing another stylesheet, you should use the order of precedence.

<head>
    <title>Title</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
    <link href="style-override.css" rel="stylesheet" type="text/css" />
</head>

Here the style.css is the original and style-override.css would contain your new custom css. These styles will override the styles from style.css. This means you won't need to use !important because the style is overwritten.

Avoid !important whenever you can.

To do @import

<style type="text/css">
  @import url("style.css");
  @import url("style-override.css");
</style> 

Also as a side note if you would rather remove all styles from the page, use a css reset.

<style type="text/css">
  @import url("style.css");
  @import url("reset.css");
  @import url("style-override.css");
</style> 

Check out a CSS reset at http://meyerweb.com/eric/tools/css/reset/ and add it to reset.css.

like image 40
Kirk Avatar answered Sep 27 '22 17:09

Kirk