panthro panthro - 1 year ago 95
CSS Question

Remove important styles in CSS

Im using google places api for a place autocomplete search - the user starts typing and results pop up.

I've styled the google container using !important to override the styles. So for my desktop css through media queries I have something like:

bottom: 100px !important;
top: auto !important;

Now on my mobile css, again through media queries, I need to move the position, I need the default styles back - the styles are controlled via google in the style tag on the element. But as I have used important i cannot remove them. I have tried:

bottom: auto !important;

Which fixes the bottom position, but how can I remove the top position so that it defaults to what is in the style tag on the element. I've tried:

top: auto !important;
top: inherit !important;

But with no luck.

Answer Source

You should be able to do this by increasing specificity on your mobile css file and adding an !important value to this new value in the mobile stylesheet.

I'm not sure of your structure without seeing your html but if you can add an additional class or id to the parent container/element that is specific to mobile css and use that to target your mobile view

for example

#mymobile .classtooverride {newstyles !important;}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download