March 20, 2012

multiple "HTML" tags in HTML file: how to separate CSS rules when classes and id's can be the same?

Question by P5music

I see that multiple HTML tag file is correctly rendered by the browser. I mean like two html files merged and concatenated. But if I put a STYLE region into each of the HTML parts and the classes or id’s are the same I get the last css rules applied also to the first part. I ask how to make css rules acting just on the part they are inserted, even the classes and ids are the same. I need this special thing, so I am looking for a solution or a trick.

Answer by stefan bachert

I think multiple html-Tags in one document are not allowed.
I do not see any advantages for doing so.

When you have multiple documents, consider to use the frame or better iframe-tag

Answer by Starx

Having multiple elements with same id is very error prone. Breaks on more than one occasion like

On javascript: document.getElementById('idname');

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!