Connexo pointed out the answer, but the extension may be useful to you and others who come here in the future.
The "style" of an HTML element can be set in at least 3 places. The browser will have to decide which one should win if a conflict arises. The rules used are called "specificity." There is a good article on this topic here https://css-tricks.com/specifics-on-css-specificity/ if you want a more complete explanation.
Just about any style defined in the attribute of the initial HTML style is the most powerful, so it wins the CSS file rule. It is important to note that setting the style, as you did in your use case, works with the HTML style attribute.
Therefore, your CSS will be overridden by setting the style attribute in your code.
For a clean JS solution, you can look at adding a listener to the window's onResize event. If you are exploring this approach, keep in mind that in some browsers an event fires for each resize pixel, so look for a solution that takes this into account like this , otherwise the function will run several times and may reduce the joy you bring to your users.
source share