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)