个人CSS笔记

body { min-width: 200px; max-width: 980px; font-family: "Helvetica Neue", Helvetica, "Segoe UI", Arial, freesans, sans-serif; font-size: 16px; line-height: 1.6; background-color: #fff; color: #333; margin: 0 auto; padding: 45px }
* { }
img { border: 0; max-width: 100% }
hr { overflow: hidden; background: transparent; border-bottom: 1px solid #ddd; height: 4px; background-color: #e7e7e7; border: 0 none; margin: 16px 0; padding: 0 }
input { margin: 0 }
a { color: #4078c0; text-decoration: none }
a:hover,a:active { text-decoration: underline }
h1,h2,h3,h4,h5,h6 { margin-top: 1em; margin-bottom: 16px; font-weight: 700; line-height: 1.4 }
h1 { padding-bottom: .3em; font-size: 2.25em; line-height: 1.2; border-bottom: 1px solid #eee }
h2 { padding-bottom: .3em; font-size: 1.75em; line-height: 1.225; border-bottom: 1px solid #eee }
h3 { font-size: 1.5em; line-height: 1.43 }
h4 { font-size: 1.25em }
h5 { font-size: 1em }
h6 { font-size: 1em; color: #333 }
blockquote { color: #333; border-left: 4px solid #ddd; margin: 0; padding: 0 15px }
blockquote>:first-child { margin-top: 0 }
blockquote>:last-child { margin-bottom: 0 }
ul,ol { margin-top: 0; margin-bottom: 0; padding: 0 0 0 2em }
ol ol,ul ol { list-style-type: lower-roman }
ul ul ol,ul ol ol,ol ul ol,ol ol ol { list-style-type: lower-alpha }
p,blockquote,ul,ol,dl,table,pre { margin-top: 0; margin-bottom: 16px }
ul ul,ul ol,ol ol,ol ul { margin-top: 0; margin-bottom: 0 }
li>p { margin-top: 16px }
pre { font: 12px Consolas, "Liberation Mono", Menlo, Courier, monospace; background-color: #f7f7f7; border: 1px solid #eaeaea; overflow: auto; font-size: 85%; line-height: 1.45; padding: 16px }
pre code { display: inline; max-width: initial; overflow: initial; line-height: inherit; background-color: transparent; font-size: 85%; margin: 0; padding: .2em 0 }
pre code::before,pre code::after { content: normal }
ul.task-list { list-style-type: none; padding-left: 20px }
ul.task-list+.ul.task-list { margin-top: 3px }
ul.task-list input { vertical-align: middle; margin: 0 .35em .25em -1.6em }
.footnotes { border-top: 1px solid #ccc }
.footnote { display: table; width: 100%; font: 14px Consolas, "Liberation Mono", Menlo, Courier, monospace }
.footnote p { margin: 8px }
.footnote .footnote-index { display: table-cell; width: 1% }
.footnote .footnote-body { display: table-cell }
mark { background-color: #e2e2e2; color: #000; padding: 2px 8px }
.hljs-comment,.hljs-quote { color: #006a00 }
.hljs-keyword,.hljs-selector-tag,.hljs-literal { color: #aa0d91 }
.hljs-name { color: #008 }
.hljs-variable,.hljs-template-variable { color: #660 }
.hljs-string { color: #c41a16 }
.hljs-regexp,.hljs-link { color: #080 }
.hljs-title,.hljs-tag,.hljs-symbol,.hljs-bullet,.hljs-number,.hljs-meta { color: #1c00cf }
.hljs-section,.hljs-class .hljs-title,.hljs-type,.hljs-attr,.hljs-built_in,.hljs-builtin-name,.hljs-params { color: #5c2699 }
.hljs-attribute,.hljs-subst { color: #000 }
.hljs-formula { background-color: #eee; font-style: italic }
.hljs-addition { background-color: #baeeba }
.hljs-deletion { background-color: #ffc8bd }
.hljs-selector-id,.hljs-selector-class { color: #9b703f }
.hljs-doctag,.hljs-strong { font-weight: bold }
.hljs-emphasis { font-style: italic }

定位模型

  • Flow(流动模型)(默认)
  • Float(浮动模型)
  • Layer(层模型)

定位方式

  1. static定位:没有特别的设定,遵循基本的定位规定,不能通过z-index进行层次分级。
  2. relative定位:对象不可层叠、不脱离文档流,参考自身静态位置通过top,bottom,left,right 定位,并且可以通过z-index进行层次分级。
  3. absolute定位: 脱离文档流,通过 top,bottom,left,right 定位。选取其最近一个最有定位设置的父级对象进行绝对定位,如果对象的父级没有设置定位属性,absolute元素将以body坐标原点进行定位,可以通过z-index进行层次分级
  4. fixed定位: 这里所固定的参照对像是可视窗口而并非是body或是父级元素。可通过z-index进行层次分级。
  • 如果找到一个设置了position:relative/absolute/fixed的元素, 就以该元素为基准定位,如果没找到,就以浏览器边界定位,
  • absolute元素是根据最近的定位上下文确定位置, 而fixed永远根据浏览器确定位置
  • 不会受空间限制,会超过容器尺寸
  • absolute元素脱离了文档结构。和relative不同,其他三个元素的位置重新排列了。
  • 只要元素会脱离文档结构,它就会产生破坏性,导致父元素坍塌。
  • (此时你应该能立刻想起来,float元素也会脱离文档结构)
  • absolute元素具有“包裹性”。之前<p>的宽度是撑满整个屏幕的,
  • 而此时<p>的宽度刚好是内容的宽度。 如果该元素是块级元素,元素的宽度由原来的 width: 100%(占据一行), 变为了 auto
  • absolute元素具有“跟随性”。虽然absolute元素脱离了文档结构,
  • 但是它的位置并没有发生变化,还是老老实实的呆在它原本的位置,
  • 因为我们此时没有设置top、left的值。
  • absolute元素会悬浮在页面上方,会遮挡住下方的页面内容
  • 设置absolute会使得inline元素被“块”化,这在上一节将display时已经说过; 该元素将变为块级元素,相当于给该元素设置了 display: block
  • 设置absolute会使得元素已有的float失效。不过float和absolute同时使用的情况不多;
  • 上文提到了absolute会使元素悬浮在页面之上,如果有多个悬浮元素,层级如何确定?
  • 答案是“后来者居上”

块级元素:

  1. 每个块级元素都从新的一行开始,并且其后的元素也另起一行。(真霸道,一个块级元素独占一行)
  2. 元素的高度、宽度、行高以及顶和底边距都可设置。
  3. 元素宽度在不设置的情况下,是它本身父容器的100%(和父元素的宽度一致),除非设定一个宽度

    <address>联系方式信息。
    <article>文章内容。
    <aside> 伴随内容。
    <audio>音频播放。
    <blockquote>块引用。
    <canvas> 绘制图形。
    <dd>定义列表中定义条目描述。
    <div>文档分区。
    <dl> 定义列表。
    <fieldset>表单元素分组。
    <figcaption> 图文信息组标题
    <figure> 图文信息组
    <footer> 区段尾或页尾。
    <form>表单。
    <h1>, <h2>, <h3>, <h4>, <h5>, <h6> 标题级别 1-6.
    <header>区段头或页头。
    <hgroup> 标题组。
    <hr>水平分割线。
    <noscript> 不支持脚本或禁用脚本时显示的内容。
    <ol>有序列表。
    <output> 表单输出。
    <p>行。
    <pre>预格式化文本。
    <section> 一个页面区段。
    <table> 表格。
    <tfoot>表脚注。
    <video> 视频。
    <ul>无序列表。

行级元素:

  1. 和其他元素都在一行上;
  2. 元素的高度、宽度及顶部和底部边距不可设置;
  3. 元素的宽度就是它包含的文字或图片的宽度,不可改变。
    b, big, i, small, tt
    abbr, acronym, cite, code, dfn, em, kbd, strong, samp, var
    a, bdo, br, img, map, object, q, script, span, sub, sup
    button, input, label, select, textarea

盒子模型

  • 加上box-sizing: border-box;之后,设完width,再设padding,和border的宽度,就会挤压content了,不会撑开。

弹性盒子 flex

  • flex-direction 设置fb子元素的方向
  • flex-wrap 设置折行模式
  • flex-flow 合并上两个属性
  • justify-content 设置子元素在主轴的对齐方式
  • align-content 设置子元素在交叉轴的对齐方式
时间: 2024-08-18 09:37:26

个人CSS笔记的相关文章

HTML+CSS笔记 CSS中级 颜色&长度值

颜色值 在网页中的颜色设置是非常重要,有字体颜色(color).背景颜色(background-color).边框颜色(border)等,设置颜色的方法也有很多种: 1.英文命令颜色 语法: p{color:red;} 2.RGB颜色 这个与 photoshop 中的 RGB 颜色是一致的,由 R(red).G(green).B(blue) 三种颜色的比例来配色 p{color:rgb(133,45,200);} 每一项的值可以是 0~255 之间的整数,也可以是 0%~100% 的百分数. 每

css笔记(二)——几种常用的模式

文本垂直居中 对于行内元素,height会自动收缩到包裹住文本的高度,所以不存在这个问题.但是对于block和inline-block等盒子元素,如果设置了height属性,则文本默认会在上方显示.如果希望文本在垂直方向上居中,可以设置line-height属性等于height属性,或者大于height属性 <div> hello world </div> div { height: 200px; line-height: 200px; } 文本水平居中,图标分列左右两侧 效果是左

css笔记-display属性

css笔记-display属性 display属性可取值 display:none | inline | block | list-item | inline-block | table | inline-table | table-caption | table-cell | table-row | table-row-group | table-column | table-column-group | table-footer-group | table-header-group | co

css笔记-选择器详解

css笔记-选择器详解 CSS通过选择器来定位要应用样式的元素. 下面对所有的选择器做了一个解释(CSS为版本号). CSS选择器详解 选择器 例子 例子描述 CSS .class .intro 选择 class="intro" 的所有元素. 1 #id #firstname id="firstname" 的所有元素. 1 * * 选择所有元素. 2 element p 选择所有 <p> 元素. 1 element,element div,p 选择所有

HTML/CSS笔记归纳整理

前言: 前端无非就是围绕标签.属性.属性值这三个词展开的. *HTML基本语法: 1. 常规标签 <标签 属性1="属性值1" 属性2="属性值2"></标签> # 一个标签可以没有属性也可以有多个属性, 属性和属性之间不分先后顺序. 2. 空标签 <标签 属性1="属性值1" 属性2="属性值2" /> # 空标签没有结束标签, 用"/"代替. *HTML标题: <

HTML+CSS笔记 CSS进阶再续

CSS的布局模型 清楚了CSS 盒模型的基本概念. 盒模型类型, 我们就可以深入探讨网页布局的基本模型了.布局模型与盒模型一样都是 CSS 最基本. 最核心的概念. 但布局模型是建立在盒模型基础之上,又不同于我们常说的 CSS 布局样式或 CSS 布局模板.如果说布局模型是本,那么 CSS 布局模板就是末了,是外在的表现形式. CSS包含3种基本的布局模型,用英文概括为:Flow.Layer 和 Float. 在网页中,元素有三种布局模型:1.流动模型(Flow)2.浮动模型 (Float)3.

HTML+CSS笔记--1

(初接触html+css时一些笔记) 1.父盒子的高可以不用给,让里面的内容撑起来就好. 2.对于外边距合并问题,解决方法overflow : hidden;,或者是另外加一个边框可以下来. 3.对于网站的logo,我们要给它设置关键字,写在a元素里, 1 .logo a{ 2 display: block; 3 height: 40px; 4 text-indent: -2000em;/*首行缩进 em是一个字的大小,rem是以一个根的大小 这个字是给搜索引擎看的*/ 5 } 4.我们可以将具

HTML+CSS笔记 CSS中级 缩写入门

盒子模型代码简写 回忆盒模型时外边距(margin).内边距(padding)和边框(border)设置上下左右四个方向的边距是按照顺时针方向设置的:上右下左. 语法: margin:10px 15px 12px 14px;/*上设置为10px.右设置为15px.下设置为12px.左设置为14px*/ 通常有三种缩写的方法: 1.如果top.right.bottom.left的值相同, margin:10px 10px 10px 10px; 可缩写为: margin:10px; 2.如果top和

HTML+CSS笔记 CSS进阶续集

元素分类 在CSS中,html中的标签元素大体被分为三种不同的类型:块状元素.内联元素(又叫行内元素)和内联块状元素. 常用的块状元素有: <div>.<p>.<h1>...<h6>.<ol>.<ul>.<dl>.<table>.<address>.<blockquote> .<form> 常用的内联元素有: <a>.<span>.<br>

HTML+CSS笔记 CSS进阶

文字排版 字体 我们可以使用css样式为网页中的文字设置字体.字号.颜色等样式属性. 语法: body{font-family:"宋体";} 这里注意不要设置不常用的字体,因为如果用户本地电脑上如果没有安装你设置的字体,就会显示浏览器默认的字体.(因为用户是否可以看到你设置的字体样式取决于用户本地电脑上是否安装你设置的字体.) 现在一般网页喜欢设置"微软雅黑" 关于字体的问题可以参考阮一峰的经典文章:http://www.ruanyifeng.com/blog/20