html 如何让文本垂直居中?让一段文字在整个页面里上下左右都居中

html-css011

html 如何让文本垂直居中?让一段文字在整个页面里上下左右都居中,第1张

1、首先我们打开自己的电脑,找到已经安装好的Dreamweaver,新建一个html页面,并保存到桌面上。

2、然后我们在html的编辑窗口,编辑元素,使其中显示若干文字,我是用的div标签进行布局显示的。

3、其在浏览器中的显示效果如下图所示,我们可以很清晰的看到,文字明显的靠上靠左对齐。

4、接下来我们就需要为文字元素添加一定的对齐方式,首先我们让其居中对齐,即使用text-align:center

5、使用之后在浏览器中进行效果查看,可以很清楚的看到,文字相对于之前靠右对齐了。

6、我们可以从上一个图中看到,文字在垂直方向上还是不对齐的,接下来我们就需要为文字添加垂直对齐样式,line-height,我们需要将这一样式的大小设为文字外层元素的高度大小,这样便可正好垂直居中对齐了。

7、接下来我们刷新浏览器中的页面,查看效果,现在的文字已是垂直水平均居中的状态。

注意事项:line-height的值和height的值要相等。

行高 line-height:数值 | inherit | normal

字间距 letter-spacing: 数值 | inherit | normal

显示 display:

none: 不显示,使用的场景非常多

block: 把内联标签变成块级标签

inline: 把块级标签变成内联标签

inline-block:变为行间块元素

宽度 width: 长度 | 百分比 | auto

高度 height: 长度 | 百分比 | auto

清除 clear: none | left | right | both

外边距 margin: 上 右 下 左

内边距 padding: 上 右 下 左

定位 position: absolute | relative

超出 overflow: visible | hidden | scroll auto

浮动 float: left | right | none在页面布局的时候用的最多

fixed 一般用来写网页顶端的固定导航条,或者两侧的菜单。

absolute与relative 这两者一般配合使用,用于调整div之间的相对位置

opacity 0-1 表示透明度

颜色 color: 数值

大小 font-size: 数值

字体 font-family: "Courier New", Courier, monospace, "Times New Roman", Times, serif, Arial, Helvetica, sans-serif, Verdana

样式 font-style: oblique(偏斜体) italic(斜体) normal(正常)

粗细 font-weight: bold(粗体) lighter(细体) normal(正常)

背景 background: transparent/透视背景*/

颜色 background-color: 数值

图片 background-image: url() | none

重复 background-repeat: inherit | no-repeat | repeat | repeat-x | repeat-y

大小写 text-transform: capitalize | uppercase | lowercase | none

修饰 text-decoration: underline(下划线) overline(上划线) line-through(删除线) blink(闪烁)

排列 text-align: justify | left | right | center

缩进 text-indent: 数值 | inherit

阴影 text-shadow:数值

边框样式 border-style: dotted(点线) dashed(虚线) soliddouble(双线) groove(槽线) ridge(脊状) inset(凹陷) outset

边框宽度 border-width:

边框颜色 border-color: top值 right值 bottom值 left值

类型 list-style-type: disc | circle | square | decimal | lower-roman | upper-roman | lower-alpha | upper-alpha | none

位置 list-style-position: outside | inside

图像 list-style-image: URL

简写 list-style:目录样式类型 | 目录样式位置 | url

margin-top:10px(上边界)

margin-right:10px(右边界)

margin-bottom:10px(下边界值)

margin-left:10px(左边界值)

margin-inside:

margin-outside:

padding-top:10px/ 上边框留空白 /

padding-right:10px/ 右边框留空白 /

padding-bottom:10px/ 下边框留空白 /

padding-left:10px/ 左边框留空白 /

vertical-align:sub/ 下标字 /

vertical-align:super/ 上标字 /

vertical-align:top/ 垂直向上对齐 /

vertical-align:bottom/ 垂直向下对齐 /

vertical-align:middle/ 垂直居中对齐 /

vertical-align:text-top/ 文字垂直向上对齐 /

vertical-align:text-bottom/ 文字垂直向下对齐 /

a / 所有超链接 /

a:link / 超链接文字格式 /

a:visited / 浏览过的链接文字格式 /

a:active / 按下链接的格式 /

a:hover / 鼠标转到链接 /

光标形状 cursor:hand | crosshair | text | wait | move | help | e-resize | nw-resize | w-resize | s-resize | se-resize | sw-resize

/ 也可以自定义 /

cursor: hand/ 链接手指 /

cursor: crosshair / 十字体 /

cursor: s-resize / 箭头朝下 /

cursor: move / 十字箭头, 朝右/

cursor: help / 加一问号 /

cursor: w-resize / 箭头朝左 /

cursor: n-resize / 箭头朝上 /

cursor: ne-resize / 箭头朝右上 /

cursor: nw-resize / 箭头朝左上 /

cursor: text / 文字型/

cursor: se-resize / 箭头斜右下 /

cursor: sw-resize / 箭头斜左下/

cursor: wait / 漏斗