htmlcss里面一个div里的ul怎么让他居中对齐?

html-css010

htmlcss里面一个div里的ul怎么让他居中对齐?,第1张

1、首先先打开我们的开发环境新建一个web项目。

2、在html中引入css文件这里是html页面的代码div和ul。

3、将所有标签的margin和padding初始为0然后将父级div的display设置为flexalign-items设置为center。

4、运行web项目后得到的结果如图所示垂直居中了。

5、 将display设置为table-cell,将vertical-align设置为middle即可。

6、将ul的高度设置为百分比然后使用相对定位设置top为二分之一的百分之百减去ul的高度即可。

7、使用line-height将其设置div的高度必须是确定值,然后将li左或者右浮动即可。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">

<head>

  <title>鼠标移动显示</title>

  <meta http-equiv="Content-Type" content="text/htmlcharset=utf-8"/>

  <meta name="description" content=""/>

<script type="text/javascript" src="js/jquery-1.8.0.js"></script> 

<style type="text/css">

ul,li{

margin:0px

padding:0px

list-style: none

}

ul{

height:31px

border-bottom:1px solid #f46d52

}

li{

width:100px

height:30px

border-radius:5px 5px 0px 0px

border:1px solid #ccc

border-bottom:none

text-align: center

line-height: 30px

background-color:#EEEEEE

float: left

color:black

font-weight: 800

margin-left:5px

}

li:hover{

height:31px

background-color: white

color:#FDE7D2

border:1px solid #f46d52

border-bottom:none

cursor:pointer

}

</style> 

</head>

<body>

<div class="nav">

<ul>

<li>导航1</li>

<li>导航2</li>

<li>导航3</li>

</ul>

</div>

</body>

</html>

效果图:

这个只是简单的.hover事件,如果要点击得到效果那个需要写js。。。

这个没影响,html的最大好处就是没有太过死板的规则,浏览器检测过后没有问题就说明可以使用。

单做页面的话可以用dreamweaver之类的软件,有些软件定义的html规则过于老套,实践是检验是否可靠的标准,只要做出来没问题就没必要理会某些软件的提示。

想要找多几个人说这个问题,你应该找个论坛,发个帖子,而不是百度知道。。。