批改状态:合格
老师批语:
.CSS { font-size:16px; }
html{ font-size:16px; }
根元素定义 font-size rem 就会按这个值定义
rem: 根据根元素的字号来设置 1rem = 10px;
盒模型, 定义边界是否包含 padding 和 border 的值box-sizing:border-box
box-sizing:content-box
一般我们写 CSS 样式都会先写初始化
<style>* {margin: 0;padding: 0;box-sizing: border-box;}</style>
浏览器用于显示文档的界面就是视口
手机端为了显示全 PC 界面,默认为 980px
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
浏览器设备当前界面默认被等分为 100
<!-- 例:定义宽为 50%,高为 25% --><style>.box {background-color: lightgreen;width: 50vw;height: 25vh;}</style>
<style>/* 自定义字体 */@font-face {font-family: "my_iconfont";src: url("font_ico/iconfont.eot");src: url("font_ico/iconfont.eot?#iefix") format("embedded-opentype"), url("font_ico/iconfont.woff2")format("woff2"), url("font_ico/iconfont.woff") format("woff"), url("font_ico/iconfont.ttf")format("truetype"), url("font_ico/iconfont.svg#iconfont") format("svg");}/* 定义一个类来引用自定义的字体my_iconfont */.iconfont2 {font-family: "my_iconfont" !important;font-size: 16px;font-style: normal;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;}</style>
引入到 html 中<span class="iconfont2"></span>
<link rel="stylesheet" href="./iconfont.css">
<span class="iconfont icon-xxx">https://www.php.cn/code/36264.htmlposition:statkic 默认定位
控制偏移:
top: 5em;left: 4em;right: 3em;bottom: 2em;
相对定位
position:relative
相对于他在的文档流中的父级或上级进行定位
<style>.box {position: relative;top: 5em;left: 4em;}</style>
绝对定位
position:absolute;
绝对定位元素脱离了文档流
文档流:显示顺序与书写顺序一致
生成绝对定位的元素,相对于 static 定位以外的第一个父元素进行定位。
<style>.box {position: absolute;top: 5em;left: 4em;}</style>
<style>.box {position: fixed;top: 5em;left: 4em;}</style>
<style>.box {position: sticky;top: 5em;left: 4em;}</style>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号