0

本体よりも幅の広い要素を作成しようとしていますが、水平スクロールは発生しません。

http://jsfiddle.net/hYRGT/

これはうまくいけば、私の問題をある程度示しています。#header には #imghead が含まれ、960px 幅に設定されています。

私が欲しいのは、ブラウザがページの幅が 960px であると「考える」ことです。#imghead は #header よりも幅が広く、相対的に配置されているため、中央に配置されています。

#imghead が Flash コンポーネントに置き換えられるため、背景画像を使用できません。

また、要素を 960px の外に表示したいので、overflow:hidden も使用できません。私はそれがhスクロールを引き起こしたくないだけです。

h スクロールを完全に無効にしたくありません。CSS ソリューションが大好きです。しかし、JavaScript がこれに対処する唯一の方法である場合は、それで十分だと思います。

4

2 に答える 2

0

左から50%、内側の要素で、要素自体の全幅の半分の負の左マージンを作成して、それを中央に配置することはできませんか?

于 2010-09-08T15:28:15.073 に答える
0

欲しかったものを手に入れたと思います: http://jsfiddle.net/hYRGT/3/

jsfiddle がダウンした場合に備えて:

HTML

<!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" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />

<title>WEBSITE title</title>

</head>
<body>
    <div id="header">
        <div id="imghead"><img src="/img.jpg" alt=""/></div>
    </div>
    <div id="wrapper" class="index">
        <div id="container">SOME CONTENT</div>
    </div>
</body>

CSS:

/*RESET*/
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,dd,dl,dt,li,ol,ul,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;font-family:inherit;font-weight:inherit;font-style:inherit;text-align:left;vertical-align:baseline}
table{border-collapse:collapse;border-spacing:0}
a img,:link img,:visited img{border:0}
address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal}
ol,ul{list-style:none}
caption,th{text-align:left}
h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal}
q:before,q:after{content:''}
abbr,acronym{border:0}
img{display:block}
a{color:inherit}

/*STYLES*/
html, body{
height:100%}
body{
background:#000;
text-align:center;
overflow:auto;
overflow-x:hidden;
overflow-y:auto}

#wrapper{
    z-index:12;
    position:relative;
    height:auto!important;
    min-height:100%;
    width:100%;
    background:#0f0;
    overflow:auto;
    overflow-x:auto;
    overflow-y:visible}
#container{
    width:960px;
    margin:0 auto;
    overflow:auto;
    background:#00f}

#header{
    z-index:50;
    position:relative;
    overflow:visible;
    width:960px;
    margin:0 auto;
    height:0px;
    background:#f00}
#imghead{
    width:1100px;
    position:relative;
    left:-70px;
    background:#ff0}

コンテンツは設計上ヘッダーと重なっています。これが誰かの役に立てば幸いです。

1 つの制限は、ヘッダーが水平方向にスクロールしないことですが、私の設計では必要ありません。

FF3、IE8、S4、および C5 でテスト済み

于 2010-09-09T07:38:29.467 に答える