Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deactivate "element.style" in css/html?

I see this css code in the "style" tab of the Chrome developer tools window:

element.style {
    height: auto;
    width: 100%;
    margin-top: -148px;
}

I want to overwrite it with this css code in my .css file:

.so-widget-sow-simple-masonry-simple-masonry-d75171398898 .sow-masonry-grid-item img {
    width: auto;
    height: 244px;
    margin-top: 0px;
    margin-left: auto;
    margin-right: auto; 
}

But the style definitions of the element.style is already there. I cant find the .js so fast. Can someone help me? Thx

like image 333
moxmlb Avatar asked Jan 02 '26 03:01

moxmlb


1 Answers

What you see in the chrome developer window as element style is the styles on a element which are written inline

element.style {
 /*this all are the inline written styles*/
}

Now coming to the point But with this codes the element.style is allready there you are not able to overwrite the styles because of the CSS Priorities. In this scenario the rule is Inline CSS has more priority than external CSS

So what can you do??

  1. You have to either remove the inline css where ever its written. That way your external css will apply

  2. If you cannot modify the inline CSS for some reason then only option is to set the styles as !important in your external CSS files. People here have already mentioned this solution, But this is not always recommended.

  3. Take all the Inline CSS written on that element and create a new class in your external file and then put it there, Now give this class name to the element. So the original styles are applied back. Now comes the point to your new Styles that you have to override. Also the new CSS priority rule when using 2 classes. CSS rule which is read last (in the css file, not the order you put in the element) will have priority. So make sure you place the new CSS rule below the other class you just created as mentioned above.

    • What if you have to use 2 separate files to write these 2 classes?? Then comes one more CSS priority rule. The file that is placed last in the DOM will have the priority (remember its not when the file is loaded into the DOM, its about where its placed in the DOM)
like image 156
Rajshekar Reddy Avatar answered Jan 03 '26 15:01

Rajshekar Reddy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!