摘要:本文全部使用内容高度不够时,依然显示到最下面大概有这样的结构布局查看下面的不需要查看不定宽高的垂直水平居中首先,兼容性也不错可以,不想用时可以用垂直水平居中居中
本文全部使用 scss + autoprefixer
Brower support: flex box(IE 10+), :before & :after IE 8+(IE8 only supports the single-colon)
内容高度不够时,footer 依然显示到最下面
大概有这样的 html 结构
</>复制代码
flex 布局
</>复制代码
html {
height: 100%;
}
$footer-height: 30px;
body {
min-height: 100%;
display: flex;
flex-direction: column;
}
#content {
flex: 1;
}
#footer {
line-height: $footer-height;
text-align: center;
}
查看 demo
-margin & padding
</>复制代码
html, body {
height: 100%;
}
$footer-height: 30px;
#content {
min-height: 100%;
margin-bottom: -$footer-height;
padding-bottom: $footer-height;
// requires box-sizing: border-box;
// 下面的不需要 border-box
/*
&::after {
content: "";
display: block;
height: $footer-height; // footer height
}
*/
}
#footer {
line-height: $footer-height;
text-align: center;
}
查看 demo
absolute center不定宽高的垂直水平居中
首先 flex
</>复制代码
.center-flex {
display: flex;
justify-content: center;
align-items: center;
}
transform
</>复制代码
.center-transform {
img {
position: relative; left: 50%; top: 50%;
transform: translate(-50%, -50%);
}
}
table-cell
</>复制代码
.center-tb-cell {
display: table-cell;
text-align: center; vertical-align: middle;
}
:after,兼容性也不错可以,不想用 table-cell 时可以用
</>复制代码
.center-ib {
text-align: center;
&::after {
content: "";
display: inline-block; vertical-align: middle;
height: 100%;
}
img {
vertical-align: middle;
}
}
垂直水平居中 demo
Cenerting float居中浮动元素
</>复制代码
.center-float {
// 父容器会产生滚动条
float: left; position: relative; left: 50%;
> ul {
position: relative; left: -50%;
}
}
float 居中 demo
Autohiding scrollbars for IEIE 自动隐藏滚动条 (works in Edge and IE10/11)
</>复制代码
html {
-ms-overflow-style: -ms-autohiding-scrollbar;
}
以下是针对移动端 (mobile)的
Tap highlight点击时高亮背景
</>复制代码
.item {
-webkit-tap-highlight-color: rgba(0,0,0,0); // 隐藏系统自带的背景
// add `ontouchstart` attribte on body
// to allow :active work (if :active not work)
&:active {
background: #ECECEC
}
}
只添加上面的样式,:active 在移动端不一定(已经引入 zepto 的已经包含下面的 js 了)生效,需要下面的js
</>复制代码
document.body.addEventListener("touchstart", function() {}, false);
// 也可以直接在body上添加 `ontouchstart` 属性,
Half pixel border
移动端半像素的边框
:after + scale(0.5) (可以是某一到两个边,或者全部边(支持圆角))
svg background
svg border-image
查看 demo
移动端常用的 cells 布局
查看微信我页面 demo (cell + tap highlight + half pixel border)
smooth scroll in webkit平滑滚动
</>复制代码
-webkit-overflow-scrolling: touch;
</>复制代码
原文地址:https://uedsky.com/2016-05/front-end-css-summary/
获取最佳阅读体验并参与讨论,请访问原文
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/115254.html
摘要:前言对于前端的性能话题,从来都没有断绝过。作为一个前端开发者,性能是我们关注的指标。前端发展以来,优化方式,琳琅满目,有雅虎军规等。所以,接下来我会从三个方面就前端性能进行总结网络方面操作及渲染方面数据方面。 前言 对于前端的性能话题,从来都没有断绝过。因为这个东西没有最好,只有更好。而且往往也是业务的繁杂程度去决定优化程度的。作为一个前端开发者,性能是我们关注的指标。它直接影响着我们...
摘要:前言对于前端的性能话题,从来都没有断绝过。作为一个前端开发者,性能是我们关注的指标。前端发展以来,优化方式,琳琅满目,有雅虎军规等。所以,接下来我会从三个方面就前端性能进行总结网络方面操作及渲染方面数据方面。 前言 对于前端的性能话题,从来都没有断绝过。因为这个东西没有最好,只有更好。而且往往也是业务的繁杂程度去决定优化程度的。作为一个前端开发者,性能是我们关注的指标。它直接影响着我们...
摘要:前言对于前端的性能话题,从来都没有断绝过。作为一个前端开发者,性能是我们关注的指标。前端发展以来,优化方式,琳琅满目,有雅虎军规等。所以,接下来我会从三个方面就前端性能进行总结网络方面操作及渲染方面数据方面。 前言 对于前端的性能话题,从来都没有断绝过。因为这个东西没有最好,只有更好。而且往往也是业务的繁杂程度去决定优化程度的。作为一个前端开发者,性能是我们关注的指标。它直接影响着我们...
摘要:向已被访问的链接添加样式。让背景图片大小水平方向扩大一倍,这样才有移动与变化的空间。不足及改进总结来看,自己做得不够,虽然也花了时间,不过能看出有敷衍的成分在。 一、前言 百度的前端技术学院IFE,2016年就听说了,当时自己也报名,还组成队伍了,不过自己一个任务也没完成就结束了,遗憾... 关注了IFE,知道2017年2月有新的一期培训,于是一直在等着报名,然后开始做里面发布的任务(...
阅读 3700·2021-11-24 10:25
阅读 2706·2021-11-24 09:38
阅读 1328·2021-09-08 10:41
阅读 3101·2021-09-01 10:42
阅读 2759·2021-07-25 21:37
阅读 2089·2019-08-30 15:56
阅读 996·2019-08-30 15:55
阅读 2838·2019-08-30 15:54