【问题标题】:Centering Text in IE 7 / Conditional CSS在 IE 7 / 条件 CSS 中居中文本
【发布时间】:2009-08-20 00:13:20
【问题描述】:
我真的很想知道这个。
除了 IE7 之外,该网站在所有方面看起来都很棒,而且我已经尝试了我所知道的一切以使其居中。
http://talentforceinc.com/Employer_Home.html
我已经为 IE 声明了条件 CSS,并添加了内联 text-align:center 标签,但由于未知原因,左侧多色条中的文本没有居中。
有什么想法吗?
是的,我知道现在的代码很丑陋 - 但在我试图集中注意力时,这一切都搞砸了。
提前感谢您的任何意见。
IE 开发者工具与 Firebug 不同......
【问题讨论】:
标签:
css
internet-explorer-7
conditional
【解决方案1】:
作为参考,所引用的页面位于此处:http://talentforceinc.com/Employers_Home.html。
参考的具体代码在这里:http://www.i-simplyrecruit.com/isrjobs/talentforce/ShowJobColors.asp,也如下所示供参考。
第一个问题是(正如您提到的),代码很丑陋。如此丑陋,以至于很难看到:
- “Cementing Service...”和“Document Layout Specialist”单元格中有未完成的 HTML 空间实体 ( )。这会导致后面的部分结束标记被忽略。
- 宽度和高度的 HTML 属性仅为整数值。不要指定“px”。前任。 450 而不是 450 像素。
- 每个单元格中的结束
标记(带有“侧边栏”类)放置在结束
和 |
之后。
修复这些错误后,我还注意到您将表格宽度设置为 185,每个表格单元格宽度设置为 100。这是为了防止表格单元格占据表格的整个宽度,使文本在它们无法在表格宽度内居中。删除单元格宽度可解决此问题。
我已经上传了一个测试页面,上面有未修改的原始代码和我的更改结果:http://demo.raleighbuckner.com/so/1303302/
原始 HTML 供参考:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://demo.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Latest Jobs</title>
<link href="http://www.talentforceinc.com/talentforce.css" rel="stylesheet" type="text/css" />
<!--[if LTE IE 7]>
<link href="http://www.talentforceinc.com/talentforce_IE.css" rel="stylesheet" type="text/css" />
<![endif]-->
<style type="text/css">
<!--
td {
text-align: center;
align: center;
}
-->
</style>
<script type="text/javascript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
function ShowMore(pID)
{
var pParm = "Candidates_jobSearch3.asp?id=" + pID;
MM_openBrWindow(pParm,"jobDetail","scrollbars=yes,width=600,height=600 resizable=no");
}
//-->
</script>
</head>
<body>
<table width=185px bgcolor=white border=0 cellpadding=0 cellspacing=0 style='text-align:center'><tr><td height=40 width=100px align=center style='text-align:center' valign=middle bgcolor='#00AADD'><div class='sidebar'><div align='center'><a style='text-align:center' href='#' onclick='javascript:ShowMore("P0006008-0032");'>Contractor Engineer Specialist</a></div></td></tr></div><tr><td height=40 width=100px align=center style='text-align:center' valign=middle bgcolor='#AADDEE'><div class='sidebar'><div align='center'><a style='text-align:center' href='#' onclick='javascript:ShowMore("N0003008-0077");'>.Net & Sql server An</a></div></td></tr></div><tr><td height=40 width=100px align=center style='text-align:center' valign=middle bgcolor='#FFCC55'><div class='sidebar'><div align='center'><a style='text-align:center' href='#' onclick='javascript:ShowMore("S5696007-0004");'>Cementing Service Sup/Deep&nbs</a></div></td></tr></div><tr><td height=40 width=100px align=center style='text-align:center' valign=middle bgcolor='#22AA55'><div class='sidebar'><div align='center'><a style='text-align:center' href='#' onclick='javascript:ShowMore("S4082007-0012");'>Coil Tubing Operator/Equipment</a></div></td></tr></div><tr><td height=40 width=100px align=center style='text-align:center' valign=middle bgcolor='#9999AA'><div class='sidebar'><div align='center'><a style='text-align:center' href='#' onclick='javascript:ShowMore("L0008004-0157");'>Loads Analysis </a></div></td></tr></div><tr><td height=40 width=100px align=center style='text-align:center' valign=middle bgcolor='#EE9922'><div class='sidebar'><div align='center'><a style='text-align:center' href='#' onclick='javascript:ShowMore("D6452009-0448");'>Document Layout Specialist&nbs</a></div></td></tr></div><tr><td height=40 width=100px align=center style='text-align:center' valign=middle bgcolor='#CCCCCC'><div class='sidebar'><div align='center'><a style='text-align:center' href='#' onclick='javascript:ShowMore("L0008004-0161");'>Technical Trainer </a></div></td></tr></div><tr><td height=40 width=100px align=center style='text-align:center' valign=middle bgcolor='#00AAAA'><div class='sidebar'><div align='center'><a style='text-align:center' href='#' onclick='javascript:ShowMore("A0029005-0025");'>Q.A. Engineer </a></div></td></tr></div><tr><td height=40 width=100px align=center style='text-align:center' valign=middle bgcolor='#888888'><div class='sidebar'><div align='center'><a style='text-align:center' href='#' onclick='javascript:ShowMore("E0001008-0090");'>Clerk Secret Clearance</a></div></td></tr></div></table>
</body>
</html>
【解决方案2】:
有时当你的代码搞砸了,你只需要下注并重新开始。
无序列表比单列表更好。
ul.nav {list-style:none;padding:0;}
ul.nav li {width: 200px; height: 40px; line-height:40px; vertical-align:middle; text-align:center;}
ul.nav li a {color:#fff;text-decoration:none;}
.man {background-color:#ade;}
.tech {background-color:#fc5;}
.hr {background-color:#2a5;}
<ul class="nav">
<li class="man"><a href="#">Man</a></li>
<li class="tech"><a href="#">Tech</a></li>
<li class="hr"><a href="#">HR</a></li>
</ul>