Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset all CSS for one element and its children

Tags:

html

css

My Problem:

We offer full customization for our site to our customers (so they can make out app look like the rest of there site). They provide us a HTML "surround" page, which our main app is rendered into (no iFrame, the HTML of our app is string.replaced() server side essentially). They can include any JS and CSS links to style this "surround" page.

The problem is, they often include their main CSS file for there full website (totally unnecessary, but easiest method to make there part look right), which includes lots of generic rules. Our app then obviously then obeys these rules, and it breaks a lot of our default styles. Specific example, they have a 'h3' rule which sets text-transform and font-family

h3 {
  text-transform: uppercase;
  font-family: 'Fjalla One',sans-serif;
}

In our own CSS, we set a the font-family of a class that is applied to the h3 tag, but not the text-transform property. As such, our CSS changes the font-family, but we inherit the text-transform.

Is there any way I can tell the browser to "start again" with applying CSS from a given element? I know its very un-Cascading, but I need the users CSS to stop cascading past our apps first element, and then apply our CSS to that element and its children. I hope i've explained myself clearly.

like image 963
Matthew Peel Avatar asked Apr 26 '17 08:04

Matthew Peel


People also ask

How do you reset everything in CSS?

There is a property called all that is being proposed for resetting all CSS properties for a given element to certain CSS-wide values - the value you want to use would be unset , which resets a property to either its inherited value if it inherits by default, or otherwise, its initial value.

How do you reset the style of an element in CSS?

Answer: Use the CSS all Property You can simply use the CSS all property with the value revert to remove the additional author-defined CSS styling for an element (i.e. reset to browser's default CSS styling).

How do I remove a style from a specific element?

removeProperty() method is used to remove a property from a style of an element. The style of the element is selected by going through the styleSheets array and selecting the cssRule. The removeProperty method can then be specified with the property to be removed.

How do I remove all properties from a element in CSS?

You can use the all property to unset all properties.


1 Answers

Option 1:

Give them a class like remove-all-styles

  .remove-all-styles {
        all: revert;
   }

Then write your css code below this css code and make sure your css has higher priority than their css file.

What is the order of loading the CSS files in a HTML page?

Option 2:

Give initial or auto values to all elements in css then write your css code below

https://www.w3schools.com/cssref/css_default_values.asp

like image 64
Yash Yadav Avatar answered Oct 26 '22 22:10

Yash Yadav