Question

I am noob in CSS and HTML, So bear with me for this question.

I am integrating a web application with our existing application. They defined some css rules which is conflicting with our application.

My problem is: Is there any good way to separate out the CSS rules to be used each application pages? I tried to look at CSS namespace, seems to be lot of rework, as I have to prepend each tag element with namespace.

Update: I am trying to integrate a Meteor based app into another Meteor based application, now I don't want the 2 css two mix.

Was it helpful?

Solution 4

I ended up following solution which worked out for me.

For another app which i am integrating, i made its whole body into a container and gave a class to it.

In layout of another app,

<!-- Another application body layout-->
<body>
<div class="another-app-container">
  <!-- Here goes whole layout of page -->
   <p  class='someClass' > ....
     <div class='myClass'> </div>

   </p>
</div>

</body

In CSS of that app, i applied following CSS rule,

    .another-app-container * .someclass{
    // CSS rule goes here
    }
   .another-app-container * .myClass {
    // CSS rule goes here
    }

Beauty of CSS i got here is, '*' which applied the CSS rules even it has lot of nesting of elements CSS.

So, it segregated the CSS for my own from another application

OTHER TIPS

Apply a class to the body per page/module/application. This way your current CSS will still work and you can override by prepending your new CSS with the body class.

CSS namespace is the only good option. You can edit all rules very easily using multiediting feature of sublime text.

Depending on the size of your application, a very dirty and quick solution is to append the rules that your need to separate files (and apply appropriately)

e.g.

for main.html, you have main.css
about.html, have about.css

however, this is pretty bad practice as your separating all your requests for essentially the same information...

What you COULD do is use a CSS Preprocessing language within your dev environment, like SASS, SCSS or LESS where you could abstract a lot of the specific pages into modular files like, main.sass, about,sass etc... which would be compiled into just one main.css file.

Another thing to consider, is that CSS is how classes, ids and pseudo selectors all effect the specificity of the rules that can be applied.

i.e.

!important > #id > .class > html_element

Here is a great intro article about CSS Specificity for you~ http://coding.smashingmagazine.com/2007/07/27/css-specificity-things-you-should-know/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top