css常用操作

一、css display

1、元素隐藏

display:none://元素隐藏后,不占用布局空间

visibility:hidden://元素隐藏后,继续占用布局

2、块级元素 block

块级元素(block)特性:

总是独占一行,表现为另起一行开始,而且其后的元素也必须另起一行显示; 宽度(width)、高度(height)、内边距(padding)和外边距(margin)都可控制;

块级元素主要有:

address , blockquote , center , dir , div , dl , fieldset , form , h1 , h2 , h3 , h4 , h5 , h6 , hr , isindex , menu , noframes , noscript , ol , p , pre , table , ul , li

3、内联元素 inline

内联元素(inline)特性:

和相邻的内联元素在同一行; 宽度(width)、高度(height)、内边距的top/bottom(padding-top/padding-bottom)和外边距的top/bottom(margin-top/margin-bottom)都不可改变,可以改变里面文字或图片的大小;

内联元素主要有:

a , abbr , acronym , b , bdo , big , br , cite , code , dfn , em , font , i , img , input , kbd , label , q , s , samp , select , small , span , strike , strong , sub , sup ,textarea , tt , u , var

4、可变元素

根据上下文关系确定该元素是块元素还是内联元素,可变元素主要有:

applet ,button ,del ,iframe , ins ,map ,object , script

5、应用

  • display:block  -- 显示为块级元素
  • display:inline  -- 显示为内联元素
  • display:inline-block -- 显示为内联块元素,表现为同行显示并可修改宽高内外边距等属性

将<ul>元素加上display:inline-block样式,原本垂直的两个列表就可以水平显示;

将<li>元素加上display:inline样式,原本垂直的列就可以水平显示。

原文地址:https://www.cnblogs.com/waxdl/p/9081426.html