0

ヘッダーを垂直方向に固定し、絶対水平方向に固定しようとしています。次のコードを使用しています。

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="style.css" rel="stylesheet" type="text/css">
<script src="header_position.js" type="text/javascript"></script>
</head>

ボディタグ

$(window).scroll(function(event) {
$("#headerpos").css("margin-left", 0-$(document).scrollLeft());
});



#headerpos{
position:fixed;
border-top:8px solid #8DC540;
background:#1E415B;
width:956px;
padding-bottom:7px;
margin:auto;
z-index:100;
 }

class attrbdivと id attrbを使用してみました

.header{
position:fixed;
border-top:8px solid #8DC540;
background:#1E415B;
width:956px;
padding-bottom:7px;
margin:auto;
z-index:100;
 }

また、削除してみましたmargin:auto;

これはすべてリンクから見ました「位置:相対」コンテナDiv内でDivを「固定」垂直および「絶対」水平に配置します

しかし、それは機能していません.Chromeで要素を検査すると、エラーが表示されます:

Uncaught Reference エラー: $ が定義されていません (1 行目)

助けてください。それは非常に重要です。

4

3 に答える 3

0

css で固定配置を使用している場合、js で div を水平方向に中央揃えにする必要はありません。これを試して。

.header{
   position:fixed;
   border-top:8px solid #8DC540;
   background:#1E415B;
   width:956px;
   padding-bottom:7px;
   margin-left:-478px;
   left:50%;
   z-index:100;
}
于 2013-04-08T20:26:28.160 に答える