Solved

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

Posted on 2016-10-25
5
61 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
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
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…

778 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