Web前端-CSS必备知识点

更新日期: 2019-03-06 阅读: 2.5k 标签: css

css基本内容,类选择符,id选择符,伪类,伪元素,结构,继承,特殊性,层叠,元素分类,颜色,长度,url,文本,字体,边框,块级元素,浮动元素,内联元素,定位。

链接:

<link rel="stylesheet" type="text/css" href="sheet.css" title="default">

link标签:

<link rel="stylesheet" type="text/css" href="sheet.css" title="default">

样式:

h1 { color: red; };

@import指示引入多个外部样式表的链接

<style type="text/css">
@import url(styles.css);
p { color: red };
</style>

css注解

/* dashucoding */

内联样式:

<p style="color: red;" >dashucoding</p>

规范:
选择符 + 声明

p { color: red; } // 选择符 属性 值
p { font-weight: bold; }

伪类和伪元素

属性说明
:link超链接是一个未访问过的地址
:visited访问过的网页
:active处于活跃的状态
a { color: red; }; a:visited { color: red; };

伪元素:

:first-letter  和  :first-line 首字母 和 首行
p:first-letter { color: red; }

css有个特点是继承,可以依赖于祖先-后代关系。

!important有这个标记,表示这条规则优先

p { color: red !important; }

元素分类:

三种类型:块级元素,内联元素,列表项元素

块级元素有段落,标题,列表,表格,div,body等。内联元素有a,em,span等。列表项元素有li元素。

dispaly: block | inline | list-item | none

颜色:

rgb(100%, 100%, 100%) 红蓝绿 ,白色

单位:

em 给字体的font-size值

文本:
文本缩进

text-indent <长度> | <百分比>
p { text-indent: -4em; }

text-align属性

用于元素中文本行的对齐方式
text-align: left | center | right | justify

white-space空白

white-space pre | nowrap | normal
p { white-space: normal; } 将如何空白压缩成单个空白符

white-space属性值为pre,可以将元素内的空白忽略。

p { white-space: pre; }

行高:

line-height文本行的基线间的距离。

纵向对齐,vertical-align

vertical-align: baseline使元素的基线同父元素的基线对齐。

vertical-align: sub; vertical-align: super;

低端对齐: vertical-align

顶端对齐:vertical-align

vertical-align: top; vertical-align: text-top;

中间对齐:

vertical-align: middle;

文字间隔:

word-spacing 长度 | normal
word-spacing: 0.3em;

字母间隔:

letter-spacing: 长度 | normal

文本转换:

text-transform uppercase | lowercase | capitalize | none

文本修饰:

text-decoration: none | overline | line-through

框:

width 长度 | 百分比 | auto
height 长度 | auto
margin 长度 | 百分比 | auto
margin: top right bottom left
margin-top
margin-right
margin-bottom
margin-left

border-width // thin medium thick
border-style: none;

padding

浮动与清除

float: left | right | none
<img src="" style="float: right"; alt="dashu">
float: none 用于防止元素浮动

清除浮动元素

clear left | right | both | none

clear原理是增加元素的上边界,使它在低于浮动元素的位置结束,清除元素的上边界宽度当有效地忽略。

list-style-type disc

disc | circle | square | decimal | upper-alpha | lower-alpha | upper-roman | lower-roman | none

list-style-type
disc 为实心圆
circle 为空心圆
square 实心或空心方块

列表项图像

list-style-image <url> | none

列表项位置:list-style-position

list-style-position: inside | outside

定位:

position: static | relative | absolute | fixed | inherit

溢出:

overflow: visible | hidden | scroll | auto | inherit

溢出剪切:

overflow-clip: rect | auto | inherit

元素剪切:

clip rect | auto | inherit

元素可见性:

visibility: visible | hidden | collapse | inherit

相对定位:

position: relative;

绝对定位:

position: relative;

固定定位:

position: fixed;

层叠定位:

z-index: integer | auto

轮廓:

outline, outline-color, outline-style, outline-width

边框:

border-top-color, border-right-color, border-bottom-color

border-left-color, border-top-style
border-right-style, border-left-style

实例:

<table cellspacing=0 border cellpadding="10">
 <tr>
  <td rowspan=2>dashu</td>
  <td colspan=2>dashu2</td>
 </tr>
 
 <tr>
   <td>1</td>
   <td>2</td>
 </tr>
</table>

本文内容仅供个人学习、研究或参考使用,不构成任何形式的决策建议、专业指导或法律依据。未经授权,禁止任何单位或个人以商业售卖、虚假宣传、侵权传播等非学习研究目的使用本文内容。如需分享或转载,请保留原文来源信息,不得篡改、删减内容或侵犯相关权益。感谢您的理解与支持!

链接: https://fly63.com/article/detial/2245

相关推荐

css完美解决网页在iphoneX的头部刘海显示问题

css完美解决iphonX白条,网站扩展到整个屏幕,CSS Shapes中有个CSS属性名为shape-outside实现元素滚动自动环绕iPhone X刘海

HTML/CSS中的空格处理_如何保留页面中的空格

在html中内容中的多个空格一般会被视为一个,连续的多个空格符被自动合并了,同时内容前后的空格也会被清除。HTML空格保留的方式、CSS空格保留的方式。

css自动省略号...,通过css实现单行、多行文本溢出显示省略号

网页开发过程中经常会遇到需要把多行文字溢出显示省略号,这篇文章将总结通过多种方法实现文本末尾省略号显示。

css中 出现height为100%失效的原因及解决方案

我们都知道需要给html和body标签设置了高度height:100%之后,再给内部的div设置height:100%的时候,内部div的高度100%才会起到作用。这是由于:%是一个相对父元素计算得来的高度,要想使他有效,我们需要设置父元素的height。

工作中常用且容易遗忘的css样式整理,建议收藏

单行文本的溢出显示省略号(一定要有宽度),中英文自动换行,设置placeholder的字体样式,不固定高宽 div 垂直居中的方法,IOS 页面滑动卡顿,设置滚动条样式

深入理解letter-spacing,word-spacing的对比区别

word-spacing 属性增加或减少单词间的空白(即字间隔)。 letter-spacing 属性增加或减少字符间的空白(字符间距)。

你知道我们平时在CSS中写的%都是相对于谁吗?

编写CSS的时候,经常会用到百分比赋值(%)实现自适应。像我们最常使用的流式布局设计模式,基本所有的column的宽度都是通过%来取值的。或者比如经常会遇到的元素水平垂直居中问题

CSS3 clip-path 用法介绍

clip-path属性可以创建一个只有元素的部分区域可以显示的剪切区域。区域内的部分显示,区域外的隐藏。剪切区域是被引用内嵌的URL定义的路径或者外部svg的路径,或者作为一个形状例如circle().。clip-path属性代替了现在已经弃用的剪切 clip属性。

css禁止选中文本_兼容实现禁用选择功能

有时候,我们需要使页面内容不可选择。首先想到的是一个css属性:user-select。user-select有两个值:none:用户不能选择文本 ,text:用户可以选择文本

CSS 解析原理_你知道浏览器CSS是如何解析吗?

作为前端,我们每天都在与CSS打交道,那么CSS的原理是什么呢? 浏览器渲染过程分为了两条主线:其一,HTML Parser 生成的 DOM 树;其二,CSS Parser 生成的 Style Rules ;

点击更多...

内容以共享、参考、研究为目的,不存在任何商业目的。其版权属原作者所有,如有侵权或违规,请与小编联系!情况属实本人将予以删除!