分享

移动端项目常用html头及css整理

 WindySky 2017-09-27

使用rem布局(js动态改变根字体大小),兼容pc端,设计稿750px

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>无标题文档</title>
  6. <meta name="keywords" content="关键字"/>
  7. <meta name="description" content="描述"/>
  8. <!--360浏览器渲染模式优先级:极速/ie兼容/ie标准-->
  9. <meta name="renderer" content="webkit|ie-comp|ie-stand">
  10. <!--ie8模拟专用:优先使用GCF渲染,否则使用最高版本的ie内核-->
  11. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  12. <!--禁止用户缩放-->
  13. <meta name="viewport" content="user-scalable=no,width=device-width,initial-scale=1,maximum-scale=1">
  14. <!--禁止自动识别邮箱、电话号码及地址-->
  15. <meta name="format-detection" content="telephone=no,email=no,address=no">
  16. <!--QQ浏览器私有-->
  17. <meta name="x5-fullscreen" content="true"><!--全屏模式-->
  18. <meta name="x5-orientation" content="portrait"><!--强制竖屏-->
  19. <meta name="x5-page-mode" content="app"><!--应用模式-->
  20. <!--UC浏览器私有-->
  21. <meta name="full-screen" content="yes"><!--全屏模式-->
  22. <meta name="screen-orientation" content="portrait"><!--强制竖屏-->
  23. <meta name="browsermode" content="application"><!--应用模式-->
  24. <!--360浏览器-->
  25. <meta name="360-fullscreen" content="true"><!--全屏模式-->
  26. <!--IOS私有:删除默认的苹果工具栏和菜单栏(即启用WebApp全屏模式)-->
  27. <meta name="apple-mobile-web-app-title" content="添加至主屏幕后的标题">
  28. <meta name="apple-mobile-web-app-capable" content="yes">
  29. <meta name="apple-touch-fullscreen" content="yes">
  30. <!--favicon icon-->
  31. <link rel="shortcut icon" href="app/statics/images/icon/favicon.ico" type="image/x-icon"/>
  32. <link rel="bookmark" href="app/statics/images/icon/favicon.ico" type="image/x-icon"/>
  33. <!--ios icon-->
  34. <!--如果不想系统对图标添加效果,则使用rel="apple-touch-icon-precomposed"-->
  35. <link rel="apple-touch-icon" sizes="60x60" href="app/statics/images/icon/apple-icon-60x60.png"/>
  36. <link rel="apple-touch-icon" sizes="76x76" href="app/statics/images/icon/apple-icon-76x76.png"/>
  37. <link rel="apple-touch-icon" sizes="120x120" href="app/statics/images/icon/apple-icon-120x120.png"/>
  38. <link rel="apple-touch-icon" sizes="152x152" href="app/statics/images/icon/apple-icon-152x152.png"/>
  39. <!--css-->
  40. <link rel="stylesheet" href="css/common.css" type="text/css">
  41. <style id="mycss"></style>
  42. <script>
  43. (function(doc,win){
  44. var docEl = doc.documentElement,
  45. mycss = doc.getElementById("mycss"),
  46. isIOS = navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
  47. dpr = isIOS ? Math.min(win.devicePixelRatio, 3) : 1,
  48. dpr = window.top === window.self ? dpr : 1, //被iframe引用时,禁止缩放
  49. resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';
  50. docEl.dataset.dpr = dpr;
  51. var recalc = function(){
  52. var width = docEl.clientWidth;
  53. mycss.innerHTML = "";
  54. if(width/dpr > 750){
  55. width = 750 * dpr;
  56. mycss.innerHTML = "body{width:750px;margin-right:auto!important;margin-left:auto!important;}";
  57. }
  58. docEl.dataset.width = width;
  59. docEl.dataset.percent = 100 * (width / 750);
  60. docEl.style.fontSize = 100 * (width / 750) + 'px';
  61. };
  62. recalc();
  63. if(!doc.addEventListener) return;
  64. win.addEventListener(resizeEvt,recalc,false);
  65. })(document,window);
  66. </script>
  67. <!--other js-->
  68. </head>

相关文章:html头部常用<meta>整理

common.css

  1. @charset "utf-8";
  2. *{padding:0;margin:0}
  3. html{
  4. font-size:100px;line-height:1;
  5. font-family:sans-serif,Microsoft Yahei;
  6. -webkit-text-size-adjust:100%;
  7. -ms-text-size-adjust:100%;
  8. text-size-adjust:100%;
  9. }
  10. body,html{-webkit-overflow-scrolling:touch}
  11. body{box-sizing:border-box}
  12. a,body,input,input:focus,select,select:focus,textarea,textarea:focus{-webkit-tap-highlight-color:rgba(0,0,0,0);outline:0;-webkit-appearance:none}
  13. li,ul{list-style-type:none}
  14. table{border-collapse:collapse;border-spacing:0}
  15. fieldset,img{border:0}
  16. legend{display:none}
  17. a{text-decoration:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;-khtml-user-select:none;user-select:none;-moz-user-focus:ignore;-moz-user-input:disabled;}
  18. a:active,a:hover,button{outline:0}
  19. input[type=checkbox],input[type=radio]{box-sizing:border-box}
  20. button,input[type=button],input[type=submit],input[type=reset]{border:0;cursor:pointer}
  21. textarea{resize:none}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多