【问题标题】:HTML responsive font size for mobile devices移动设备的 HTML 响应式字体大小
【发布时间】:2013-07-28 04:21:39
【问题描述】:

我有一个在 Android 和 IOS 上运行的应用程序。
该应用程序有一些显示 HTML
的 WebView 组件 从我发现有“em”和“viewport”单位 以及 css 中的“@media”。

我是 HTML5 和 CSS3 的新手,谁能给我看一个移动设备的响应式字体大小示例。
对我来说最重要的是手机和平板有不同的字体大小, 还可以在不同屏幕尺寸的移动设备之间(纵向和横向)。

编辑:

WebView 组件不是全屏的,它们是文本框的大小,并且大小是动态的。

【问题讨论】:

    标签: android ios html css responsive-design


    【解决方案1】:

    在媒体查询中使用

    HTML

    <p class="fonts">Administrator</p>
    

    添加媒体查询

      @charset "utf-8";
        /* CSS Document */
        /* Smartphones (portrait and landscape) ----------- */
        @media only screen
        and (min-device-width : 320px)
        and (max-device-width : 480px) {
         .fonts
         {
          font-size: 75%;
         }    
        }
        /* Smartphones (landscape) ----------- */
        @media only screen
        and (min-width : 321px) {
         .fonts
         {
          font-size: 120%;
         }  
        }
        /* Smartphones (portrait) ----------- */
        @media only screen
        and (max-width : 320px) {
         .fonts
         {
          font-size: 120%;
         }  
        }
        /* iPads (portrait and landscape) ----------- */
        @media only screen
        and (min-device-width : 768px)
        and (max-device-width : 1024px) {
         .fonts
         {
          font-size: 120%;
         }    
        }
        /* iPads (landscape) ----------- */
        @media only screen
        and (min-device-width : 768px)
        and (max-device-width : 1024px)
        and (orientation : landscape) {
         .fonts
         {
          font-size: 150%;
         }    
        }
        /* iPads (portrait) ----------- */
        @media only screen
        and (min-device-width : 768px)
        and (max-device-width : 1024px)
        and (orientation : portrait) {
    
         .fonts
         {
          font-size: 120%;
         }  
        }
        /* Desktops and laptops ----------- */
        @media only screen
        and (min-width : 1224px) {
         .fonts
         {
          font-size: 156%;
         }    
        }
        /* Large screens ----------- */
        @media only screen
        and (min-width : 1824px) {
         .fonts
         {
          font-size: 200%;
         }    
        }
        /* iPhone 4 ----------- */
        @media
        only screen and (-webkit-min-device-pixel-ratio : 1.5),
        only screen and (min-device-pixel-ratio : 1.5) {
         .fonts
         {
          font-size: 190%;
         }    
        }
    

    我使用 % 作为字体大小,这里只是字体大小的示例,尝试一下并添加您认为最好的 %

    【讨论】:

    • 如果WebView不是全屏呢?
    • 我不知道 Webview,但这是在 css 中完成的,并且检查了屏幕分辨率,我想你有一个视图,它读取一个 css 文件?
    【解决方案2】:

    最简单的方法是使用 % 或 em 中的尺寸。只需将基本字体大小设置为设备的默认值,然后全部放在 em 中。

    一路看https://stackoverflow.com/a/21981859/406659

    【讨论】:

      猜你喜欢
      • 2013-04-09
      • 2014-10-09
      • 2015-01-20
      • 2012-07-02
      • 1970-01-01
      • 1970-01-01
      • 2018-08-30
      • 2012-02-28
      • 2020-08-22
      相关资源
      最近更新 更多