【发布时间】:2014-07-09 13:10:46
【问题描述】:
我想做的是制作一个清晰的 div 框以跨浏览器(Mozilla、Chrome、Opera、IE 9+、Safari)+ IE 6、7 和 8 工作,如下图所示:
http://s29.postimg.org/8hp8m56gm/5_21_2014_12_06_38_AM.jpg
我让它在除 IE 6、7 和 8 之外的所有其他浏览器中工作。
为了解决这个问题,我利用了@potench 的回复:How does one target IE7 and IE8 with valid CSS?。这非常有帮助,但是我无法让它与 IE 6、7、8 一起使用,因为@potench 的建议只描述了如何将它与选择器一起使用(这在大多数情况下都是有意义的)。但是,我的情况不同。我的逻辑告诉我,由于我正在尝试为 IE 6、7 和 8 创建一个清晰的 div 框,因此我需要使用一个类来完成。简而言之,使用一个类来选择(sp?)另一个类。我尝试做的是使用类ie8 选择transboxBody,但这不起作用:
.ie8 transboxBody{
background-color: #fff;
filter:alpha(opacity=60);
}
我尝试在我的 HTML 中选择第二个 div 元素:
div:second-child {
background-color: #fff;
filter:alpha(opacity=60);
}
这应该选择这个 div 元素:
<div class="transboxHead">
<img src="../_images/image">
<h2>Header text</h2>
</div>
但是,这不起作用,因为它影响了 Mozilla、Chrome、Opera、IE 9+ 和 Safari 中的 div 框颜色。
总而言之:有没有更简单的方法可以做到这一点?我可以选择另一个班级的班级吗?如果没有,解决这个问题的最佳方法是什么?
请注意,我对将 Jquery 用于学习目的不感兴趣...我想让它使用尽可能干净的代码,并且拥有 Jquery 函数会增加更多内容。
这是我的代码...
CSS:
/*Zeroes out all margins*/
* {
margin:0;
padding:0;
}
/*Center align website*/
#wrapper {
width:47em;
margin:0 auto;
text-align:left;
}
body {
text-align:center; /*For IE6*/
}
/*Background image for website*/
html, body {
background-image:url("../_images/Background.jpg");
}
/*Top transparent box*/
.transboxHead {
background-color:rgba(255,255,255, 0.6);
opacity: 0.6;
border-radius: 0 0 25px 25px;
padding: 1em;
}
/*Body transparent box*/
.transboxBody {
margin:30px 0px;
background-color:rgba(255,255,255, 0.3);
border-radius:25px;
padding: 1em;
}
.ie6 transboxBody{
background-color: #fff;
filter:alpha(opacity=60);
}
/*Registartion form styling*/
.logregform li {
margin: 10px;
/*I added the width and height seen below to try to get it work in Chrome*/
padding:top;
width:220px;
height:30px;
}
/*Center fields*/
.contact_form {
width:240px;
overflow:hidden;
padding:10px;
}
/*Contact form styling*/
.contact_form ul {
list-style-type:none;
list-style-position:outside;
margin:0px;
padding:0px;
}
HTML:
<!--[if lt IE 7 ]> <html lang="en" class="ie6"> <![endif]-->
<!--[if IE 7 ]> <html lang="en" class="ie7"> <![endif]-->
<!--[if IE 8 ]> <html lang="en" class="ie8"> <![endif]-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8">
<link type="text/css" rel="stylesheet" href="../_css/stylesheet.css"/>
</head>
<div id="wrapper">
<div class="transboxHead">
<img src="../_images/image">
<h2>Header text</h2>
</div>
<div class="centered transboxBody">
<div class="logregform">
<form class="contact_form">
<ul>
<li>
</li>
<li>
</li>
<li>
</li>
<li>
</li>
<li>
</li>
<li>
</li>
</ul>
</form>
</div>
</div>
【问题讨论】:
-
IE7 和 IE8 支持子选择器,但您没有在代码中的任何地方使用它。您使用的是
:nth-child(),IE8 及更早版本确实不支持。 -
我不想使用 Jquery @mplungjan
-
所以请阅读其他答案
-
正如我所说,请阅读我给出的不使用 jQuery 的链接中的答案 - 无论如何,你似乎找到了你需要的东西
标签: html css internet-explorer-8