《css揭秘》- 47个不为人知的高阶操作🔥(下篇20-47, 7K长文多图预警)(五)

简介: 《css揭秘》- 47个不为人知的高阶操作🔥(下篇20-47, 7K长文多图预警)(五)

41-紧贴底部的页脚


背景知识:视口相关的长度单位 vw, vhcalc()

介绍:当页面较短时,底部页脚 foolter 区域不能紧贴在底部,而是紧跟在内容的下方。这里提供了2 种方案来解决这个问题。


固定高度的解决方案


1687781578759.png


<header>
  <h1>Site name</h1>
</header>
<main>
    <input type="checkbox" id="contents" /><label for="contents">Toggle contents</label>
    <p>Bacon ipsum dolor sit amet turkey veniam shankle, culpa short ribs kevin t-bone occaecat. Et laborum venison nostrud, ut veniam sint kielbasa ullamco pancetta. Qui drumstick tail, bacon leberkas shoulder capicola laborum. Minim ipsum bacon, mollit laboris t-bone pariatur. Ham hock reprehenderit sint beef, sausage pig eiusmod t-bone shankle strip steak.</p>
    <p>Cow enim excepteur, boudin dolore lorem magna fugiat consequat voluptate. Picanha fugiat chicken, cupim aliquip magna filet mignon prosciutto ut nostrud. Kielbasa rump frankfurter sunt corned beef. Andouille in cillum deserunt, rump et picanha landjaeger tongue anim.</p>
    <p>Ad meatball ipsum ground round shank. Quis ipsum meatball exercitation. Laborum swine spare ribs, sunt ball tip magna t-bone venison. Velit doner voluptate non occaecat do ribeye kevin strip steak et. Esse biltong shank ribeye dolor pariatur aute deserunt non est eiusmod pork belly pancetta pork chop. Pork chop id consectetur rump, meatball short loin brisket tail andouille deserunt alcatra irure prosciutto do.</p>
    <p>Dolore reprehenderit ex, meatball doner commodo consectetur ea ribeye. Ad aliqua kevin, chuck excepteur minim et cow esse ham hock landjaeger. Alcatra bresaola dolore tempor do, excepteur in velit flank officia dolore meatloaf corned beef picanha. Eu pancetta brisket eiusmod ipsum aute sausage, culpa rump shoulder excepteur nostrud venison sed pork loin. Tempor proident do magna ground round. Ut venison frankfurter et veniam dolore. Pig pork belly beef ribs kevin, doner exercitation magna esse shankle.</p>
    <p>Flank anim chuck boudin id consectetur bresaola ham pork loin cupim andouille frankfurter. Proident do ball tip nostrud nulla sed, frankfurter ut commodo corned beef ut. Ex aute in, pig deserunt beef ribs turducken pastrami irure ball tip pork belly pork chop sausage id. Chicken sunt nisi tempor sed. In eiusmod non fatback tempor tenderloin pastrami adipisicing cow lorem ut tail jerky cupidatat venison. Jowl consequat commodo pork loin ipsum pork belly prosciutto aute beef. Ball tip shoulder aliqua, fugiat landjaeger kevin pork chop beef ribs leberkas hamburger cillum turkey ut doner culpa.</p>
</main>
<footer>
    <p>© 2015 No rights reserved.</p>
    <p>Made with ♥ by an anonymous pastafarian.</p>
</footer>
/**
 * Sticky footer with fixed height
 */
main {
    min-height: calc(100vh - 5em - 7em);
}
/* Toggle checkbox to alternate between short/long content */
#contents:checked ~ p { display: none }
/* Basic styling */
body {
    margin: 0;
    font: 100%/1.5 Palatino Linotype, Palatino, serif;
}
h1 { margin: .5em 0 0; }
header { text-align: center; height: 3em; }
main, footer {
    display: block;
    padding: .5em calc(50% - 400px);
}
footer {
    background: linear-gradient(#222, #444);
    color: white;
    height: 6em;
}


更灵活的解决方案 Flexbox


/**
 * Sticky footer with flexible height
 */
body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
main {
    flex: 1;
}
/* Toggle checkbox to alternate between short/long content */
#contents:checked ~ p { display: none }
/* Basic styling */
body {
    margin: 0;
    font: 100%/1.5 Baskerville, Palatino Linotype, Palatino, serif;
}
h1 { margin: .5em 0 0; }
header { text-align: center; height: 3em; }
main, footer {
    display: block;
    padding: .5em calc(50% - 400px);
}
footer {
    background: linear-gradient(#222, #444);
    color: white;
}


42-缓动效果


背景知识:基本的 css 过渡,基本的 css 动画

介绍:给过渡和动画加上缓动效果可以使界面显得更加的生动和真实,毕竟在现实世界中,物体从A 点到 B 点到移动往往不是完全匀速的。

下面基于 css 动画实现了一个回弹效果


弹跳动画


1687781600078.png


<div class="ball"></div>
/**
 * Bouncing animation
 */
@keyframes bounce {
    60%, 80%, to {
            transform: translateY(400px);
            animation-timing-function: ease;
    }
    70% { transform: translateY(300px); }
    90% { transform: translateY(360px); }
}
.ball {
    width: 0; height: 0; padding: 1.5em;
    border-radius: 50%;
    margin: auto;
    background: red radial-gradient(at 30% 30%, #fdd, red);
    animation: bounce 2s cubic-bezier(.1,.25,1,.25) forwards;
}
body {
    background: linear-gradient(skyblue, white 450px, yellowgreen 0);
    min-height: 100vh;
}


弹性过渡


下面这个输入框在 focus 的时候会显示出一个 tips , 我们通过过渡和自定义调速函数 cubic-bezier() 来改善下效果,使其更加生动。


1687781611586.png


<label>
    Your username:
    <input value="leaverou"></input>
    <span class="callout">
    Only letters, numbers, underscores (_) and hyphens (-) allowed!
    </span>
</label>
                                                      /**
 * Elastic transitions
 */
input:not(:focus) + .callout:not(:hover) {
    transform: scale(0);
    transition: .25s transform;
}
.callout {
    transition: .5s cubic-bezier(.25,.1,.3,1.5) transform;
    transform-origin: 1.4em -.4em;
}
/* Styling */
body {
    padding: 1.5em;
    font: 200%/1.6 Baskerville;
}
input {
    display: block;
    padding: 0 .4em;
    font: inherit;
}
.callout {  
    position: absolute;
    max-width: 14em;
    padding: .6em .8em;
    border-radius: .3em;
    margin: .3em 0 0 -.2em;
    background: #fed;
    border: 1px solid rgba(0,0,0,.3);
    box-shadow: .05em .2em .6em rgba(0,0,0,.2);
    font-size: 75%;
}
.callout:before {
    content: "";
    position: absolute;
    top: -.4em;
    left: 1em;
    padding: .35em;
    background: inherit;
    border: inherit;
    border-right: 0;
    border-bottom: 0;
    transform: rotate(45deg);
}


反面案例-对颜色的弹性过渡


虽然这种效果挺有趣,但是在 UI 的场景下通常是不合适的。


1687781623575.png


/**
 * Elastic color
 */
html {
    background: rgb(100%, 0%, 40%);
    transition: 1s cubic-bezier(.25,.1,.2,3);
}
html:hover {
    background: gray;
}


43-逐帧动画


背景知识:基本的 css 动画,“缓动效果”

介绍: 使用 css 实现一个 loading 动画, 主要原理是对一张 png 图片进行 background-position 偏移动画。


1687781634598.png


<div class="loader">Loading…</div>
/**
 * Frame-by-frame animations
 */
@keyframes loader {
    to { background-position: -800px 0; }
}
.loader {
    width: 100px;
    height: 100px;
    text-indent: 999px;
    overflow: hidden; /* Hide text */
    background: url(http://dabblet.com/img/loader.png) 0 0;
    animation: loader 1s infinite steps(8);
}


目录
相关文章
|
19小时前
|
移动开发 前端开发 JavaScript
编程笔记 html5&css&js 005 网页上都有哪内容、形式和操作
编程笔记 html5&css&js 005 网页上都有哪内容、形式和操作
|
19小时前
|
前端开发 JavaScript
如何固定html表格头部,用css样式即可实现,操作简便、代码简单
如何固定html表格头部,用css样式即可实现,操作简便、代码简单
35 0
|
8月前
|
JSON 前端开发 JavaScript
jQuery操作CSS
jQuery操作CSS
63 0
|
10月前
|
前端开发
CSS 高阶小技巧 - 角向渐变的妙用!
CSS 高阶小技巧 - 角向渐变的妙用!
|
5月前
|
JavaScript 前端开发
【jQuery学习】—jQuery操作CSS和表格
【jQuery学习】—jQuery操作CSS和表格
|
10月前
|
存储 前端开发 JavaScript
JavaScript操作表格及CSS样式
JavaScript操作表格及CSS样式
129 0
|
10月前
|
前端开发
DSP开发软件css(10)使用基础(汉化、工程导入、设置目标配置文件、选择仿真器和芯片型号、添加文件|库路径、编译下载等操作)
DSP开发软件css(10)使用基础(汉化、工程导入、设置目标配置文件、选择仿真器和芯片型号、添加文件|库路径、编译下载等操作)
114 0
|
10月前
|
前端开发 JavaScript
使用JS操作CSS
一.什么是css? Cascading Style Sheets 通常称为CSS样式表或层叠样式表(级联样式表) CSS用于控制网页的外观 (HTML是用于控制网页结构的,JS是控制网页的行为) Css让界面变得更加美观
|
11月前
|
前端开发 流计算
《css揭秘》- 47个不为人知的高阶操作🔥(下篇20-47, 7K长文多图预警)(六)
《css揭秘》- 47个不为人知的高阶操作🔥(下篇20-47, 7K长文多图预警)(六)
102 0
|
11月前
|
前端开发
《css揭秘》- 47个不为人知的高阶操作🔥(下篇20-47, 7K长文多图预警)(四)
《css揭秘》- 47个不为人知的高阶操作🔥(下篇20-47, 7K长文多图预警)(四)
57 0

热门文章

最新文章