Solved

Using custom html tags with differnt name but exact styling as existing ones

Posted on 2016-10-25
5
72 Views
Last Modified: 2016-11-30
Hi,
I am using <ul> , <li> tags in my javascript library. This will be used by some user.. My library also has styling info for ul and li tags...
What this library does is if a user has an html element like : <div id="filter"/>
It will replace it with some new html consisting of <ul> . <li> etc... tags...
This only happens when the user passes the id of the html element to my library.
But the issue with this is that my library has a particular css included with a particular styling for ul and li element.. which i want to use for this replaced html...

But in case if user also specifies the style for ul and li elements then that may interfere with my library styling.
So i was thinking if instead of specifying ul i could specify something like <temp:ul> ie. my custom name but has the same styling as ul. So if user provides some styling for ul it doesnt override my styling.

Is there any way to achieve this ?

Thanks
0
Comment
Question by:Rohit Bajaj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 20

Accepted Solution

by:
Russ Suter earned 250 total points
ID: 41859311
You can add the !important directive to your style elements. This won't completely prevent a user from overriding your style but they'll also have to use the !important directive for it to work. There is, in fact, no way to prevent the cascading function of CSS. After all, "Cascading" is in the name.

The other thing you might be able to do is to have your Javascript code inject the CSS reference after all other CSS references on the page. That way your style changes will take priority.

Both of these approaches have a tendency to annoy people who might use the library.
0
 
LVL 43

Assisted Solution

by:Chris Stanyon
Chris Stanyon earned 250 total points
ID: 41859506
Why don't you just give your <ul> your own unique ID and then specify that in the CSS, for example:

<ul id="someUniqueId">
   ...
</ul>

ul#someUniqueId { margin: 0px; } 
ul#someUniqueId li { color: blue; }

Open in new window

0
 

Author Comment

by:Rohit Bajaj
ID: 41859734
giving an id i can prevent my style from overriding others...but not others styling overriding mine...
if the user puts some styling on ul tag then that wilp reflect on my ul tag also
0
 
LVL 20

Expert Comment

by:Russ Suter
ID: 41859741
Bottom line... There is no technique you can come up with that a coder with decent HTML, CSS, and Javascript knowledge cannot bypass, circumvent, or override if they really want to. Most people won't want to use a library or framework that uses inline styles when CSS options are being ignored.

You seem to be over constraining the problem. What are the requirements that are forcing you to use inline styles?
0
 

Author Comment

by:Rohit Bajaj
ID: 41868560
I am including a css in my js file... My js file basically provide a search filter widget with some styling. And this styling is bundled with my js file...
What other alternative ways do you suggest can i achieve this ?
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question