CSS清除默认样式H5端所有项⽬通⽤
将⼿机端设计稿的单位换算成rem,需要在⽂件中加⼊如下⼀段脚本:
<script type="text/javascript">
/* rem 尺⼨换算 1rem=100px */
(function (doc, win) {
var docEl = doc.documentElement,
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function () {
var clientWidth = docEl.clientWidth;
if (!clientWidth) return;
if(clientWidth>=640){
docEl.style.fontSize = '100px';
}else{
docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
}
};
if (!doc.addEventListener) return;
win.addEventListener(resizeEvt, recalc, false);
doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);
</script>
下⾯的代码在清除默认样式的同时,也解决了H5端的⼀些适配和样式兼容性问题,要将上⾯的JS代码与下⾯对应的CSS适配代码配合来使⽤(有些class类名是平时⾃⼰开发时的⼀些习惯):
/*---------全局重置开始----------*/
html {
/* 让⾮ie浏览器默认也显⽰垂直滚动条,防⽌因滚动条引起的闪烁 */
overflow-y: scroll;
/*设置字体*/
font-family: "PingFang", "Source Han Sans CN", "Microsoft YaHei", "Tahoma", "Helvetica", "Arial", "\5b8b\4f53", "sans-serif";
/*webkit在渲染页⾯时,会⾃动调整字体⼤⼩,⽐如横竖屏切换时*/
-webkit-text-size-adjust: 100%;
}
html * {
outline: 0;
-webkit-tap-highlight-color: rgba(0,0,0,0);
/*iOS会在元素周围显⽰橙⾊的外框,以表明该元素被tap了。如果你想⾃⼰实现tap时的响应效果,可以⽤以下⽅法“去除”这个⾼亮效果*/
}
body, ul, ol, li, dl, dt, dd, p, pre, h1, h2, h3, h4, h5, h6, hr, blockquote, fieldset, lengend,
button,
textarea,
th,
td {
margin: 0;
padding: 0;
}
article, aside, details, figcaption, figure, footer, header, hgroup,nav, section{ display:block;}
input, select, textarea {
-webkit-appearance:none; /*去掉webkit默认的表单样式*/
}
/* 表单控件没有亮线 */
button, input, optgroup, select, textarea {
margin: 0;
outline: none;
font: inherit;
border: none;
}
/
* 表格边框和元素间距清空 */
table {
table {
border-collapse: collapse;
border-spacing: 0;
}
li {
list-style: none;
}
a {
text-decoration: none;
}
em {
font-style: normal;
}
img {
border: none;
margin: 0;
padding: 0;
vertical-aline:middle;
}
/*-----全局重置结束-------*/
/
*--------盒模型兼容开始-------*/
.flex {
display: box;
/*Android 4.4*/
display: -webkit-box;
/*iOS 6-, Safari 3.1-6*/
display: -moz-box;
/*Firefox 19*/
display: -ms-flexbox;
/*IE 10*/
display: -webkit-flex;
/
*Chrome*/
display: flex;
/*Opera 12.1, Firefox 20+*/
}
/*主轴竖直*/
.flex_column {
-webkit-box-orient: vertical;
-webkit-flex-direction: column;
-moz-flex-direction: column;
-ms-flex-direction: column;
-o-flex-direction: column;
flex-direction: column;
}
.flex_wrap {
-webkit-box-lines: multiple;
-webkit-flex-direction: wrap;
-moz-flex-direction: wrap;
-ms-flex-direction: wrap;
-o-flex-direction: wrap;
flex-direction: wrap;
}
/*元素两端排列*/
.
flex_jus_between {
-webkit-box-pack: space-between;
-webkit-justify-content: space-between; -moz-justify-content: space-between; -ms-justify-content: space-between;
-o-justify-content: space-between;
justify-content: space-between;
}
/*元素两端间距排列*/
.flex_jus_around {
-webkit-box-pack: space-around;
-webkit-justify-content: space-around; -moz-justify-content: space-around;
-moz-justify-content: space-around;
-ms-justify-content: space-around;
-o-justify-content: space-around;
justify-content: space-around;
}
/*元素两端间距排列*/
css设置表格滚动条.flex_jus_center {
-webkit-box-pack: center;
-webkit-justify-content: center;
-moz-justify-content: center;
-ms-justify-content: center;
-o-justify-content: center;
justify-content: center;
}
/*元素竖直⽅向居中*/
.flex-ali_i_center {
-webkit-box-align: center;
-webkit-align-items: center;
-moz-align-items: center;
-ms-align-items: center;
-o-align-items: center;
align-items: center;
}
/
*多⾏元素竖直⽅向居中*/
.flex-ali_c_center {
-webkit-box-align: center;
-webkit-align-content: center;
-moz-align-content: center;
-ms-align-content: center;
-o-align-content: center;
align-content: center;
}
/*--------盒模型兼容结束-------*/
/*----------适配开始--------*/
@media screen and (max-width: 320px) { html {
font-size: 90px;
}
}
@media screen and (min-width: 320px) { html {
font-size: 90px;
}
}
@media screen and (min-width: 370px) { html {
font-size: 100px;
}
}
@media screen and (min-width: 410px) { html {
font-size: 110px;
}
}
@media screen and (min-width: 480px) { html {
font-size: 130px;
}
}
@media screen and (min-width: 560px) { html {
font-size: 150px;
}
}
@media screen and (min-width: 640px) { html {
html {
font-size: 170px;
}
}
@media screen and (min-width: 760px) {
html {
font-size: 200px;
}
}
/*----------适配结束----------*/
/*----------常⽤类名----------*/
.clearfix{*zoom:1;}
.clearfix:after{ content:""; display:block; clear:both;} .pull-right {
float: right;
}
.pull-left {
float: left;
}
.hide {
display: none;
}
.show {
display: block;
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论