7

現在、HTML5およびCSSプロジェクトに取り組んでおり、コンテナーを正しく表示するのに問題があります。

私が欲しいのは、上部のヘッダーバー、他の2つのdivを含むラッパー、そして常にウィンドウの下部またはコンテンツの下部のどちらか下にある下部のフッターです。

スニペットは次のとおりです。

html, body
{
	padding: 0;
	margin: 0;
}

#wrapper
{
	position: absolute;
	background-color: purple;
	height: 100%;
	width: 100%;
	margin-top: 0px;
}

header
{
	position: absolute;
	width: 100%;
	height: 80px;
	background-color: black;
	color: white;
}


#articleContainer
{
	background-color: blue;
	width: 75%;
	margin-left: auto;
	margin-right: auto;
	height: auto;
	margin-top: 80px;
}

#articleContent
{
	width: 70%;
	background-color: yellow;
	float: left;
}

#articleSideBar
{
	position: relative;
	width: 28%;
	background-color: green;
	float: right;
	margin-left: 2px;
	margin-right: 2px;
	display: inline;
	margin-top: 0px;
	float: right;
	height: auto;
}
<html>
	<head>
		<title>index</title>
		<link href="ArticleStyleSheet.css" rel="stylesheet" type="text/css" />
	</head>
	<body>
		<div id="wrapper">
			<header>
				Header
			</header>
			<div id="articleContainer">
				Article Container
				
				<div id="articleContent">
					The quick brown fox jumped over the lazy dogs back. All good men must come to the aid of the party
				</div>
				
				<div id="articleSidebar">
					Article Sidebar
				</div>
			</div>
		</div>
	</body>
</html>

現時点では、articleContainerは、行がいくつあっても高さだけです。画面の残りの部分を埋めるためのformContainerが必要です。高さを追加してみました:100%; 属性ですが、これは画面サイズを超えるフォームコンテナを感じます。つまり、ヘッダーとほぼ同じ高さの垂直スクロールバーが表示されます。スクロールバーなしでformContainerに利用可能な画面スペースを埋めさせるにはどうすればよいですか。ただし、コンテンツがフォームコンテナよりも大きい場合は、余分なスペースを埋めるために拡張する必要があります。

あなたが提供できるどんな助けにも感謝します。

4

2 に答える 2

7

本当にcss3ソリューションが必要な場合は、このフィドルに示されているように、探しているものが設定height: calc(100% - 80px);されていますが、これはすべてのブラウザーで機能するとは限りません。#articleContainer

古いフレックスボックスモデルcssを使用した例:

html, body
{
    padding: 0;
    margin: 0;
    height: 100%;
}

#wrapper
{
    display: -webkit-box;
    -webkit-box-orient: vertical;
    min-height: 100%;
    background-color: purple;
    width: 100%;
    margin-top: 0px;
}

header
{
    width: 100%;
    height: 80px;
    background-color: black;
    color: white;
}

#articleContainer {
    width: 75%;
    margin: auto;
    background-color: blue;
    display: -webkit-box;
    -webkit-box-flex: 1;
}

#articleContent
{
    width: 70%;
    background-color: yellow;
}

#articleSideBar
{
    position: relative;
    width: 28%;
    background-color: green;
    margin-left: 2px;
    margin-right: 2px;
    display: inline;
    margin-top: 0px;
    height: auto;
}​

同じことですが、今回は新しいフレックスボックスモデル cssを使用します

html, body
{
    padding: 0;
    margin: 0;
    height: 100%;
}

#wrapper
{
    display: -webkit-flex;
    -webkit-flex-direction: column;
    min-height: 100%;
    background-color: purple;
    width: 100%;
    margin-top: 0px;
}

header
{
    width: 100%;
    height: 80px;
    background-color: black;
    color: white;
}

#articleContainer {
    width: 75%;
    margin: auto;
    background-color: blue;
    display: -webkit-flex;
    -webkit-flex: 1;
}

#articleContent
{
    width: 70%;
    background-color: yellow;
}

#articleSideBar
{
    position: relative;
    width: 28%;
    background-color: green;
    margin-left: 2px;
    margin-right: 2px;
    display: inline;
    margin-top: 0px;
    height: auto;
}​

段落のみが黄色のバージョン

于 2012-10-18T21:34:14.137 に答える
1

私は以前にこの方法を使用しましたが、トリッキーな部分はヘッダーとフッターを正しい場所に配置することです。それができたら、残りは適切な場所に配置する必要があります。

jsfiddle:

http://jsfiddle.net/Ug5JR/

css:

html, body { margin: 0; padding: 0; height: 100%; }

header {
  position: relative;
  display: block;
  background: red;
  height: 100px;
  z-index: 1;
}

article {
  display: block;
  background: yellow;
  min-height: 100%;
  margin-top: -100px;
  margin-bottom: -100px;
}

article section {
  display: block;
  padding-top: 100px;
  padding-bottom: 100px;
  overflow: hidden;
}

footer{
  display: block;
  background: blue;
  height: 100px;
}

p:hover {
  height: 4000px;
}

マークアップ:

<header></header>
<article>
  <section>
     <p>Hover me and I'll push the content larger than the page</p>
  </section>
</article>
<footer></footer>

トリックは、ヘッダーとフッターによって使用されるスペースを吸収するために負のマージンを取得することです。これにより、100%の計算が自動的に修正されます。次に、任意の内部要素を使用して、上下のパディングまたはマージンで負のマージンに対抗できます。したがって、article要素はページのほぼ100%の高さですが、article> section要素は正しい高さに表示され、子を正しく配置します。

于 2012-10-18T21:45:25.093 に答える