javascript - 如果检测到移动用户,如何缩小表格文本?

标签 javascript html css

我的JS:

window.onload = function(){
    if(/Android|webOS|iPhone|Windows Phone/i.test(this.navigator.userAgent)){
        document.getElementById('datatable').style.fontSize = "10px";
    } else {
        document.getElementById('datatable').style.fontSize = "20px";
    }
}

HTML:

<table class="TFtable" id="datatable">
  ...
</table>

请注意:目前没有与字体大小相关的样式会影响“TFtable”类。

最佳答案

您可以使用 CSS 媒体查询来定位视口(viewport)小于 600 像素的设备。

@media only screen and (max-width: 600px) {
  table.TFtable {
    font-size: /* your smaller font size*/;
  }
}

关于javascript - 如果检测到移动用户,如何缩小表格文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61440951/

相关文章:

html - 对齐 td 内的 div

html - 仅在 Safari 中位于 div 之外的文本

javascript - Grails 资源、302、SSL 和 Chrome

c# - 寻求有关如何将 JS 代码与 View 解耦的建议

html - 防止:hover styles affecting :after content

html - 垂直对齐不同字体大小的文本

javascript - 按下回车键不会在 Mozilla 中打开下拉菜单

javascript - 箭头函数体与返回值。 ()=>{return value;} 与 ()=>value;

javascript - MDL 表检索数据检查值

javascript - 循环遍历 DOM 元素,包括 span 元素