0

css で固定された位置を使用すると、ie7 の margin-top に問題が発生します。

解決策をウェブで検索し、多くのことを試しましたが、何も機能しませんでした。

テスト div の margin-top が機能していません。

どんな助けでも大歓迎です。

これが私のhtmlです

<!DOCTYPE html>
<html lang="en">
<head>
<title> test </title>
<link rel="stylesheet" href="test.css">

<!--[if IE 7]><link rel="stylesheet" href="ie7.css" type="text/css" media="screen"/><![endif]-->



</head>

<body>
<div id="fixed1">
<div id="fixed"></div>
</div>


<div id="test">
ayhd iaudiuawdyiaudyw
</div>
<div class="clear">
</div>

</body>
</html>

ここに私のcssがあります

html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote,
pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, 
q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, 
form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
margin : 0;
padding : 0;
border : 0;
outline : 0;
font-weight : inherit;
font-style : inherit;
font-size : 100%;
font-family : inherit;
vertical-align : baseline;}
:focus {
outline : 0;
}
body {
line-height : 1;
color : black;
background : white;
}
ol, ul {
list-style : none;
}
table {
border-collapse : separate;
border-spacing : 0;
}
caption, th, td {
text-align : left;
font-weight : normal;
}


#fixed1 {
position : fixed;
width : 100%;
top : 0;
background-color : red;
}
#fixed {
margin : 0 auto;
height : 20px;
background-color : blue;
width : 980px;
}
#test {
margin : 0 auto;
margin-top : 20px;
margin-bottom : 20px;
height : 2000px;
width : 980px;
background-color : red;
}

ここにie7.cssがあります

#fixed1{
left:0px;
}

#test{
margin-top:30px;
background-color:grey;
}

ありがとう、キショア。

4

1 に答える 1

0

このフィドルを確認してください。あなたのコードをフィドルに追加しました。IE 7 でも動作しますhttp://jsfiddle.net/S9AVa/1/

問題は、margin : 0 auto; の 2 つの方法で指定されたマージンが原因でした。また、margin-top と margin-bottom です。IE は最初の呼び出しを考慮します。

次のようになるはずです

#test {
margin : 20px auto 20px auto;
float:left;
 height : 2000px;
width : 1040px;
background-color : red;
}

そして私はクラスに追加left:0;しました。fixed1

更新されたデモhttp://jsfiddle.net/S9AVa/2/

于 2012-08-29T11:00:56.113 に答える