关于css里<li>内文字 竖直居中 ?

html-css017

关于css里<li>内文字 竖直居中 ?,第1张

1.首先,打开HTML编辑器并创建一个新的HTML文件,比如index。说明:html,用于填写代码的基本层次的问题。-

2.在index.html中的<style>标签中,将“.shoucang .sc_ul li”中的“height: 73px”调整为:height: 73pxpadding-top: 7px。

3.最后,浏览器运行index.html页面,发现li标记中的文本垂直和水平居中。

扩展资料:

其他代码:

Thecodeisasfollows:

<style type = "text/CSS" >

.Shoucang{

Width:58px;

Height:300px;

Float:correct;

Background-color:#CCC;

Border:1pxentity#999;

.Shoucang.Sc_ul{

Width:21px;

Margin-right:car;

Margin-left:car;

Thelist-style-type:no;

Padding-top:20px;

Padding-right:0px;

Padding-bottom:0px;

Padding-left:0px;

Margin-top:0px;

Margin-bottom:0px;

.Shoucang.Sc_ulli{

Thetext-align:center;

Vertical-align:intermediate;

Height:80px;

Width:21px;

Margin-bottom:9px;

Color:#FFF.

Textmodification:no;

Thetext-align:center;

Vertical-align:intermediate;

Background-color:#FF0000;

Fontsize:12px;

Border:1pxentity#666;

-->

></ style

</ a >

The <body >

<div class = "shoucang" >

<ul class = "sc_ul" ><li >set as home </ li ><li >lee </ >

<li class = "no" >contact way lee </ a >

</ ul >

css垂直居中,如果兼容各个浏览器的话,我还没有见过。

在百度里面搜了很多,代码都不健壮,最终都是用js来实现的。

首先,我们来了解水平居中,它有很多种方法,我们暂时先来了解其中的几种:

1.在实现方案中,我们最熟悉的莫过于给元素定义一个宽度,然后使用margin:

body{

width:960px

margin:0 auto

}

这个是当我们的定义元素的宽度时显现的,如果我们不能定义宽度时,该怎么办呢?

2.我们对于定位也是常用的,在这里当然也可以采用定位的方法来实现:

body{

position:absolute

left:50%

}

3. 既然定位可以,那浮动也是可以的:

body{

float:left

right:50%

}

4.对于几个元素同时居中在一条线上

body{

vertical-align:middle

}

5.利用table:

ul{

display:table

}

ul li{

display:table-cell

}

6.还可以使用inline-block来实现,但要使用这个就得在其父元素上设置text-align.如下:

body{

text-align:center

}

.content{

display:inline-block

}

实现垂直居中的四种方法:

1.只能是单行文本居中(可适用于所有浏览器):

.content{

height:100px

line-height:100px

}

2.跟水平居中一样,垂直也可以用定位的方法:

.content{

position:absolute

top:0

bottom:0

left:0

right:0

margin:auto

}

或者

.content{

position:absolute

top:50%

}

定位的方法,它的缺点是当没有足够的空间时,元素会消失。

3.对此,浮动也是可以的:

.content{

float:left

height:50%

margin-bottom:-120px

}

.footer{

clear:both

height:240px

position:relative

}

对于浮动,我们需要在之后清除,并显示在中间。

4.也可以使用vertical-align属性:

.content{

display:table-cell

vertical-align:middle

}

这种方法可以随意改变元素高度,但在IE8中无效。

现在来看个div模块在屏幕中居中的例子:

position: absolute top: 50% left: 50% //上下移动屏幕的50%

margin: auto

-webkit-transform: translate(-50%,-50%)//减去自身的50%(多移动的)

-ms-transform: translate(-50%,-50%)

transform: translate(-50%,-50%)

这个基本可以不确定宽高的模块居中,但是在低版本的浏览器中可能出现问题,现在还没测试过,但是主流的都是可以的!

河南新华电脑学院为您解答