0

私は新しいウェブサイトに取り組んでおり、基本的なレイアウトを実行しようとしています。ASP.NET MVC 4で生成されたHTMLを使用していますが、のスペースを確保してブラウザウィンドウの下部に固定した後、使用可能なスペースを埋めるためにDIV名前を付けたいと思います。しかし、私が今得ているのは、3つのパネルがちょうど積み重ねられていることです。bodyheaderfooter

ブラウザがHTML5をサポートしている場合と、サポートしていない場合に機能するソリューションが欲しいのですが。

私が試したことを説明するために、CSSにコメントを挿入していることに注意してください。

HTML

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>@ViewBag.Title - Title</title>
        <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <meta name="viewport" content="width=device-width" />
        @Styles.Render("~/Content/css")
    </head>
    <body>
        <header>
            <div class="content-wrapper">
                <div class="float-left">
                    <p class="site-title">@Html.ActionLink("Title", "Index", "Home")</p>
                </div>
            </div>
        </header>
        <div id="body">
            @RenderSection("featured", required: false)
            <section class="content-wrapper main-content clear-fix">
                @RenderBody()
            </section>
        </div>
        <footer>
            <div class="content-wrapper">
                <div class="float-left">
                    <p>&copy; @DateTime.Now.Year - ACME. All rights reserved.</p>
                </div>
                <div class="float-right">
                    <ul id="social">
                        <li><a href="http://facebook.com" class="facebook">Facebook</a></li>
                        <li><a href="http://twitter.com" class="twitter">Twitter</a></li>
                    </ul>
                </div>
            </div>
        </footer>

        @RenderSection("scripts", required: false)
    </body>
</html>

CSS

body {
    /* I'VE TRIED BOTH OF THE FOLLOWING TO SEE IF THE BODY ITSELF WOULD SPAN */
    /* WITH NO OTHER CSS APPLIED TO THE body ELEMENT */

    /*height: fill-available;*/
    /*height: 100%*/
}

/* general layout
----------------------------------------------------------*/
.float-left {
    float: left;
}

.float-right {
    float: right;
}

.clear-fix:after {
    content: ".";
    clear: both;
    display: block;
    height: 0;
    visibility: hidden;
}

/* main layout
----------------------------------------------------------*/
.content-wrapper {
    margin: 0 auto;
    max-width: 960px;
}

#body {
    background-color: #efeeef;
    clear: both;
    padding-bottom: 35px;

    /* I'VE TRIED BOTH OF THE FOLLOWING TO SEE IF I COULD GET THIS ELEMENT TO SPAN */
    /* WITHOUT ANY OTHER CSS APPLIED TO THE body TAG */

    /*height: fill-available;*/
    /*height: 100%*/
}

.main-content {
    /*background: url("../Images/accent.png") no-repeat;*/
    padding-left: 10px;
    padding-top: 30px;
}

.featured + .main-content {
    /*background: url("../Images/heroAccent.png") no-repeat;*/
}

footer {
    clear: both;
    background-color: #e2e2e2;
    font-size: .8em;
    height: 100px;
}

/* site title
----------------------------------------------------------*/
.site-title {
    color: #c8c8c8;
    font-family: Rockwell, Consolas, "Courier New", Courier, monospace;
    font-size: 2.3em;
    margin: 20px 0;
}

    .site-title a, .site-title a:hover, .site-title a:active {
        background: none;
        color: #c8c8c8;
        outline: none;
        text-decoration: none;
    }

/* social
----------------------------------------------------------*/
ul#social li {
    display: inline;
    list-style: none;
}

    ul#social li a {
        color: #999;
        text-decoration: none;
    }

a.facebook, a.twitter {
    display: block;
    float: left;
    height: 24px;
    padding-left: 17px;
    text-indent: -9999px;
    width: 16px;
}

a.facebook {
    background: url("../Images/facebook.png") no-repeat;
}

a.twitter {
    background: url("../Images/twitter.png") no-repeat;
}
4

2 に答える 2

2

fixedポジショニングを使用して、ページの下部にあるヘッダーとフッターをスナップするだけです。

header, footer{ position:fixed; left:0; right:0; z-index:1; }
header{ top:0; }
footer{ bottom:0; }

body次に、以前に持っていた背景を与えることができますdiv#body。divはバックグラウンドを取得せず、必要なだけ拡張されます。

div#body{ background:none; }
body{ background:#eee; }

これはdiv、ページの残りのスペースを埋めるように見えます。最後に、その下の体の背景が見えないように、headerとを与えます。footerbackground

header, footer{ background:#fff; }

ちなみに、体の縁を取り除くことをお勧めします。body{ margin:0; }

于 2012-08-10T22:31:05.543 に答える
0

CSSだけでそれを行うのは少し不可能だと思います。次のように、高さが100%のWebページを作成できます。

html{
    height: 100%;
}

body{
    height: 100%;
}

#body{
    height: 100%;
}

そして、ヘッダー、ボディ、フッターについては、次のように実行できます。

header{
  height: 100px;
  left: 0;
  position: absolute;
  top: 0;
  width: 100%;
  background-color: #f00;
}

#body{
  bottom: 100px;
  left: 0;
  position: absolute;
  right: 0;
  top: 100px;
  background-color: #fff;
}

footer{
  bottom: 0;
  height: 100px;
  left: 0;
  position: absolute;
  width: 100%;
  background-color: #ff0;
}

少しは機能するかもしれませんが、ある時点で機能しなくなります。ブラウザのサイズを変更すると、ブラウザのスペースが不足します#body。より良い解決策が必要な場合は、javascriptを使用する必要があります。JavaScriptで、のスペースを計算してから、と#bodyの高さを調整します。または、代わりに調整してください。headerfooter#body

于 2012-08-11T00:07:52.957 に答える