简体   繁体   English

当 window 大小达到 javascript 中的某个点时,如何更改 css

[英]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.我希望当屏幕大小达到 1050 像素时调整字体。 How do i do this with javascript我如何使用 javascript 执行此操作

Add this to your css :将此添加到您的css

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

you can do it with css and javascript你可以用 css 和 javascript 来完成

CSS CSS

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

JavaScript 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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更改JavaScript滑块的大小 - How do you change the size of a javascript slider 当检测到一定的最小屏幕分辨率大小时,如何通过Javascript更改CSS属性 - How can I change a CSS attribute by Javascript when a certain minimum screen resolution size is detected 使用JavaScript更改浏览器窗口大小时如何更改div宽度 - How to Change a div width when size of browser window change with javascript 如何在图像通过页面上的某个点时更改图像,然后在图像高于该点时将其更改回来? - How do I change an image when it passes a certain point on a page, and then change it back when it is above that point? 如何在 CSS3 或 javascript 中与窗口的更改大小成比例地更改字体大小 - how to change the font-size proportionally to the change size of the window in CSS3 or javascript 如何更改JavaScript中嵌套的CSS元素的颜色? - how do you change color of nested css element in javascript? 如何更改 javascript 文件中的 CSS 属性? - How do you change a CSS property in a javascript file? 当窗口大小改变时,如何更改按钮的功能? - How do I change the function of a button when the window size changes? 当您通过 javascript 在 url 中找到特殊参数时如何更改 CSS - How to change CSS when you find a special parameter in url by javascript 如何基于Javascript中的某个位置弹出某个大小的窗口? - How to popup window of a certain size based on a certain position in Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM