DEV Community

pixman92
pixman92

Posted on

Changing CSS By Device Screen Size - Javascript

Wrote a simple JS file that pre-defines Screen Media sizes (for mobile, for tablet and beyhond) by just the change of a paramater.

https://gist.github.com/pixman92/961887a7ab28877d1529d43616a18899

Breakdown:
CSSChange(query, property, newValue) - changes a CSS element
changingBasedOnScreenSize(dynamicVar, classOfDevice, elem, attribute, newValue)

changingBasedOnScreenSize() _ parameters defined
dynamicVar - makes a Dynamic Variable
classOfDevice - grabs a preset value and matches that to logic
elem - querySelector a DOM element
attribute - what CSS element to change
newValue - what attribute of the CSS to change

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay