div 中的字体如何用CSS控制居下

html-css015

div 中的字体如何用CSS控制居下,第1张

div 中的字体如何用CSS控制居下的方法:

1、用margin-top 或者padding-top 设置。

代码:

<div class="text"></div>

.text {width:??pxheight:??pxmargin-top:10px} //这里用margin或padding 都行。

2、设置行高,line-height 属性

如:line-height:30px 数字越大行高越高 行与行的距离越大。

代码:

<div class="text"></div>

.text {width:??pxheight:??pxline-height:??px}

例:居中.wrapper里的.content

一. 已经元素的宽高的前提下:

(1)  left:50%top:50%

父元素设置相对定位,position: relative 

子元素(要居中的元素)设置绝对定位,position: absolute  left: 50%   top: 50%

(2)设置margin: auto

父元素设置相对定位,position: relative

子元素(要居中的元素)设置绝对定位,position: absolutemargin: auto

(3)   flex布局

父元素设置 display: flex  justify-content: center   align-items: center

二.未知元素宽高的情况下:

(1)四个方向设置值,把元素撑开

父元素设置相对定位,position: relative 

子元素设置绝对定位,position: absolutetop与bottom设置一样的值,left与right设置一样的值,把容器撑开

绝对居左下的方式:

图片包括任何的标签都是不能默认绝对居下的,都是需要通过css样式控制的,这个就要用到定位。给img添加一个绝对定位position:absoluteleft:0bottom:0也需要给它的某个父级添加一个相对定位。

img标签是向网页中嵌入一幅图像。

注意,从技术上讲,<img>标签并不会在网页中插入图像,而是从网页上链接图像。<img>标签创建的是被引用图像的占位空间。

<img>标签有两个必需的属性:src 属性 和 alt 属性。