简体   繁体   中英

How do you change css when window size gets to a certain point in javascript

I want the font to adjust when the sc reen size gets to 1050px. How do i do this with javascript

Add this to your css :

@media screen and (min-width: 1050px) {
    body {
        /* set font adjusters here */
    }
}

you can do it with css and javascript

CSS

@media screen and (min-width: 1050px) {
    body {
       font-size: // the value you want
    }
}

JavaScript

if(screen.width < your point) {
  // change font size
}

you need to add event listener

const handleResize = () => {
  if(window.innerHeight > 1050) {
     //you can change font size here
     document.getElementById("yourelement").style.fontSize = "69px";
  }
}
window.addEventListener('resize', handleResize)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM