Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2016-10-25
5
Medium Priority
?
85 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 1000 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 44

Assisted Solution

by:Chris Stanyon
Chris Stanyon earned 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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 …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

704 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