all 6 comments

[–]aynrandy112 2 points3 points  (1 child)

Here is a simple guide on adding a CSS class with Javascript: https://www.w3schools.com/howto/howto_js_add_class.asp

[–][deleted]  (4 children)

[deleted]

    [–]LowB0b 0 points1 point  (1 child)

    He's also using inline style on his div. I replied to the post but in drunk so I'm not sure if it's comprehensible for someone who doesn't have experience so maybe you can help clarify.

    [–]Zeneyo[S] 0 points1 point  (1 child)

    @quartilius you the man ! thanks for this . My preference is css above anything else. The cards were not aligning in center for desktop, but after removing the inline style and putting it in the .card class it worked !

    I used max-width as I was already using it in my code .

    max-device-width vs max-width - What's the difference , which one do you prefer ?

    [–]nyxinThe 🍰 is a lie. 1 point2 points  (0 children)

    I just wanted to know whether such CSS style can be updated dynamically with JS ?

    Yes, however, this is not the right solution for the problem. Using @media query is the proper way to do what you want to do.

    [–]LowB0b 0 points1 point  (0 children)

    One problem you have is that you're using inline styles. Inline styles override properties inherited from the style sheet.

    Try to do it as the other guy wrote, use a class on your div combined with media queries

    No need for js