Solved

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

Posted on 2016-10-25
5
22 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
  • 2
  • 2
5 Comments
 
LVL 20

Accepted Solution

by:
Russ Suter earned 250 total points
Comment Utility
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 42

Assisted Solution

by:Chris Stanyon
Chris Stanyon earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now