有问题先搜索一下: 高级搜索

已解决问题 - 浏览1944次

下一个已解决问题
yiciyuan@yahyiciyuan@yah

伴读书童

DIV+CSS LI里面怎么让垂直的文字垂直居中?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
<!--
.shoucang {
width: 58px;
height: 300px;
float: right;
background-color: #CCCCCC;
border: 1px solid #999999;
}
.shoucang .sc_ul {
width: 21px;
margin-right: auto;
margin-left: auto;
list-style-type: none;
padding-top: 20px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
margin-top: 0px;
margin-bottom: 0px;
}
.shoucang .sc_ul li {
height: 80px;
width: 21px;
margin-bottom: 9px;
color: #FFFFFF;
text-decoration: none;
text-align: center;
vertical-align: middle;
background-color: #FF0000;
font-size: 12px;
border: 1px solid #666666;
}
-->
</style>
</head>
<body>
<div class="shoucang">
<ul class="sc_ul"><li>设为首页</li><li>收藏本站</li>
<li class="no">联系方式</li>
</ul>
</div>
</body>
</html>

问题补充:不但要垂直居中,而且还要左右居中,IE和火狐都要能通过。。

还可输入300个字

ystsangnbsystsangnbs

解元

最佳答案 - 由投票者2008-01-25 20:32:07选出

因为IE和火孤理解CSS是不同的, 只要在shoucang的float 设为center,改<div>???</div>成<center><div>???</div></center>,火狐达标.IE是不成的,IE的的float没作用,要在sc_ul定margin-left:5%.才达标.
所以制成2张CSS表,ie.css 和ff.css.在页面中用JAVASCRIPT定出用者是IE或火狐,然后用相关的CSS.
网页是这样的
<html>
<head>
<script type="text/javascript">
function loadjscssfile(filename, filetype){
if (filetype=="css"){
var fileref=document.createElement("link");
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", filename);
}
if (typeof fileref!="undefined")
{
document.getElementsByTagName("head")[0].appendChild(fileref);
}
}

function detectBrowser()
{
var browser=navigator.appName;
if (browser=="Microsoft Internet Explorer")
{
loadjscssfile("ie.css", "css") ;
}
else
{
loadjscssfile("ff.css", "css") ;
}
}
</script>

</head>
<body onload="detectBrowser()">
<center>
<div class="shoucang">
<ul class="sc_ul">
<li>设为首页</li>
<li>收藏本站 </li>
<li>联系方式</li>
</ul>
</div>
</center>
</body>
</html>
//下面是ie.css
================
.shoucang {
width: 58px;
height: 300px;
background-color: #CCCCCC;
border: 1px solid #999999;
}

.sc_ul {
width: 21px;
margin-right: auto;
margin-left: 5%;
list-style-type: none;
padding-top: 20px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
margin-top: 0px;
margin-bottom: 0px;
}

li{
height: 80px;
width: 21px;

margin-bottom: 9px;
color: #FFFFFF;
text-decoration: none;
text-align: center;
vertical-align: middle;
background-color: #FF0000;
font-size: 12px;
border: 1px solid #666666;
//图是ff.css
================

0 0
  • enix2212enix2212

    伴读书童

    ie6能识别* 不能识别!important
    ie7能识别* 也能识别!important
    ff不能识别* 能识别!important

    比如要给ie6定义独立样式可以用
    * html #main{ }
    完全没有必要借助js编辑两个样式表

  • enix2212enix2212

    伴读书童

    ie6能识别* 不能识别!important
    ie7能识别* 也能识别!important
    ff不能识别* 能识别!important

    比如要给ie6定义独立样式可以用
    * html #main{ }

还可输入300个字

返回知识堂首页>>

生活画报

更多
1
Copyright © 2009 Yahoo.com.cn 版权所有 不得转载 | 使用须知 | 著作权声明 | 京ICP证000022号 | 国家药监局(京)-经营性-2004-0039
阿里巴巴集团 - 阿里巴巴 | 淘宝站 | 支付宝 | 口碑网
文明办网举报热线 010-65986060