css基础的一些总结

一、CSS 选择符:

    1.id选择器(# myid)

    2.类选择器(.myclassname)

    3.标签选择器(div, h1, p)

    4.相邻选择器(h1 + p)

    5.子选择器(ul > li)

    6.后代选择器(li a)

    7.通配符选择器( * )

    8.属性选择器(a[rel = external])

    9.伪类选择器(a: hover, li:nth-child)

    10.CSS3新增伪类选择器

        p:first-of-type 选择属于其父元素的首个 <p> 元素的每个 <p> 元素;

        p:last-of-type  选择属于其父元素的最后 <p> 元素的每个 <p> 元素;

        p:only-of-type  选择属于其父元素唯一的 <p> 元素的每个 <p> 元素;

        p:only-child    选择属于其父元素的唯一子元素的每个 <p> 元素;

        p:nth-child(2)  选择属于其父元素的第二个子元素的每个 <p> 元素;

        :enabled :disabled  控制表单控件的禁用状态;

        :checked        单选框或复选框被选中。

二、样式的继承

    1、可继承的属性

        1)、字体系列属性

            font:组合字体;

            font-family:规定元素的字体系列;

            font-weight:设置字体的粗细;

            font-size:设置字体的尺寸;

            font-style:定义字体的风格;

            font-stretch:对当前的 font-family 进行伸缩变形。所有主流浏览器都不支持;

            font-size-adjust:为某个元素规定一个 aspect 值,这样就可以保持首选字体的 x-height

        2)、文本系列属性

            text-indent:文本缩进;

            text-align:文本水平对齐;

            line-height:行高;

            word-spacing:增加或减少单词间的空白(即字间隔);

            letter-spacing:增加或减少字符间的空白(字符间距);

            text-transform:控制文本大小写;

            direction:规定文本的书写方向;

            color:文本颜色。

        3)、元素可见性:visibility;;

        4)、表格布局属性:caption-sideborder-collapseborder-spacingempty-cellstable-layout;

        5)、列表布局属性:list-style-typelist-style-imagelist-style-positionlist-style;

        6)、生成内容属性:quotes;

        7)、光标属性:cursor;

        8)、页面样式属性:pagepage-break-insidewindowsorphans

    2、不可继承的样式:

        1)display:规定元素应该生成的框的类型;

        2)、文本属性

                vertical-align:垂直文本对齐;

                text-decoration:规定添加到文本的装饰;

                text-shadow:文本阴影效果;

                white-space:空白符的处理;

                unicode-bidi:设置文本的方向。

        3)、盒子模型的属性:widthheightmargin margin-topmargin-rightmargin-bottommargin-leftborderborder-styl        eborder-top-styleborder-right-styleborder-bottom-styleborder-left-styleborder-widthborder-top-widthborder-rig    ht-rightborder-bottom-widthborder-left-widthborder-colorborder-top-colorborder-right-colorborder-bottom-color、    border-left-colorborder-topborder-rightborder-bottomborder-leftpaddingpadding-toppadding-rightpadding-bo    ttompadding-left

       4)、背景属性:backgroundbackground-colorbackground-imagebackground-repeatbackground-positionbackground-    attachment

       5)、定位属性:floatclearpositiontoprightbottomleftmin-widthmin-heightmax-widthmax-heightoverflow、    clipz-index

        6)、生成内容属性:contentcounter-resetcounter-increment

        7)、轮廓样式属性:outline-styleoutline-widthoutline-coloroutline

        8)、页面样式属性:sizepage-break-beforepage-break-after

        9)、声音样式属性:pause-beforepause-afterpausecue-beforecue-aftercueplay-during

三、优先级算法:

     1.优先级就近原则,同权重情况下样式定义最近者为准

     2.载入样式以最后载入的定位为准

     3.!important > id > class > tag

     4.important 比内联优先级高,但内联比 id 要高。

*注:直接数就行(只要选择同一个元素,优先级div.box > .box

四、CSS3新增样式

  1. CSS3实现圆角(border-radius),阴影(box-shadow);
  2. 对文字加特效(text-shadow、),线性渐变(gradient),旋转(transform);
  3. transform:rotate(9deg) scale(0.85,0.90) translate(0px,-30px) skew(-9deg,0deg);// 旋转,缩放,定位,倾斜;
  4. 增加了更多的CSS选择器 多背景 rgba;
  5. 在CSS3中唯一引入的伪元素是 ::selection.
  6. 媒体查询,多栏布局;
  7. border-image。

五、display的样式

    有很多:none | inline | block | inline-block | list-item | run-in | table | inline-table | table-row-group | table-header-group | table-footer-group | table-row | table-colume-group | table-column | table-cell | table-caption | inherit

下面只列举些常用的值。

inline(默认值)
1.内容撑开宽度。 
2.对它进行设置宽高度是无效的。 
3.不单独占一行,其他元素会紧跟其后。 
4.如果对inline元素设置float及position:absolute/fixed,会发现元素被“块”化,可以对其设置宽高了。

block 
1.可以设置宽高。 
2.单独占一行。 

3.宽度不设置的话,宽度为父元素的宽度。

inline-block 
可以理解为既有inline的同行特性也有block的宽高特性。可以想想一般的button、input是什么样子的。 
1.不单独占一行。 
2.可以设置宽高。

none 
1.隐藏元素并脱离文档流。 
2.和visibility的区别就在于,visibility:hidden还会保留元素本该显示的空间。但none不会。

inherit 
继承父元素的display属性的值。

table 
也是一个“块”,但和block相比,它具有包裹性。

六、position区别

1.absolute 生成绝对定位的元素,absolute的”根元素“是可以设置的,绝对定位的元素的位置相对于最近的已定位祖先元素,如果元素没有已定位的祖先元素,那么它的位置相对于最初的包含块。

2.fixed 生成绝对定位的元素,相对于浏览器窗口进行定位(老IE不支持)。

3.relative 生成相对定位的元素,相对于其在普通流中的位置进行定位。

4.static 默认值。没有定位,元素出现在正常的流中(忽略 top, bottom, left, right z-index 声明)。

5.inherit 规定从父元素继承 position 属性的值。


持续更新中。。。



猜你喜欢

转载自blog.csdn.net/linxner/article/details/80761125