0

フルページCSS3グラデーションの背景:

了解しました。背景を常に幅と高さが100%のグラデーションにしようとしていますが、その上に何も表示されないという事実を除けば、機能します。これが私が現在持っているコードです。

CSS:

<style type="text/css" media="screen">
#bodyBg{
    background:rgb(79,143,249) no-repeat center center fixed; /* Old browsers */
    background: -moz-radial-gradient(center, ellipse cover,  rgba(164,197,252,1) 1%, rgba(79,143,249,1) 100%); /* FF3.6+ */
    background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(1%,rgba(164,197,252,1)), color-stop(100%,rgba(79,143,249,1))); /* Chrome,Safari4+ */
    background: -webkit-radial-gradient(center, ellipse cover,  rgba(164,197,252,1) 1%,rgba(79,143,249,1) 100%); /* Chrome10+,Safari5.1+ */
    background: -o-radial-gradient(center, ellipse cover,  rgba(164,197,252,1) 1%,rgba(79,143,249,1) 100%); /* Opera 12+ */
    background: -ms-radial-gradient(center, ellipse cover,  rgba(164,197,252,1) 1%,rgba(79,143,249,1) 100%); /* IE10+ */
    background: radial-gradient(ellipse at center,  rgba(164,197,252,1) 1%,rgba(79,143,249,1) 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#a4c5fc', endColorstr='#4f8ff9',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */
    min-height: 100%;
    min-width: 1024px;
    width: 100%;
    height: auto;
    position: fixed;
    top: 0;
    left: 0;
    z-index:0;
}
    @media screen and (max-width: 1024px) { /* Specific to this particular image */
#bodyBg {
    left: 50%;
    margin-left: -512px;   /* 50% */
}
#body-404 {
    position: relative;
    margin: 50px auto;
    width:880px;
    text-align:center;
    color:white;
    font-family: "Helvetica Neue", "URW Palladio L", Arial, Helvetica, "Palatino Linotype";
    z-index:99;
}
</style>

HTML:

<div id="body-404">
    <img src="img/logo.png" width="100%">
    <h1><span>Sorry the page you were looking for was not found</span></h1>
    <p>If you believe you got to this page in error, please contact us via <a href="contactus.php">this page</a>.</p><br />
    <font size="120%"><a href="index.php">Return to Homepage</font>
</div>
<div id="bodyBg"></div>

デモ:

http://mysteriousorigin.com/missing.html

4

2 に答える 2

5

あなたのような空の要素を持つことは一般的に悪い習慣と考えられています#bodyBg。html(またはbody)要素に背景のグラデーションを配置して、役に立たないdivを削除するだけです。

http://jsfiddle.net/2yVRA/1/

html {
    background:rgb(79,143,249) no-repeat center center fixed; /* Old browsers */
    background: -moz-radial-gradient(center, ellipse cover,  rgba(164,197,252,1) 1%, rgba(79,143,249,1) 100%); /* FF3.6+ */
    background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(1%,rgba(164,197,252,1)), color-stop(100%,rgba(79,143,249,1))); /* Chrome,Safari4+ */
    background: -webkit-radial-gradient(center, ellipse cover,  rgba(164,197,252,1) 1%,rgba(79,143,249,1) 100%); /* Chrome10+,Safari5.1+ */
    background: -o-radial-gradient(center, ellipse cover,  rgba(164,197,252,1) 1%,rgba(79,143,249,1) 100%); /* Opera 12+ */
    background: -ms-radial-gradient(center, ellipse cover,  rgba(164,197,252,1) 1%,rgba(79,143,249,1) 100%); /* IE10+ */
    background: radial-gradient(ellipse at center,  rgba(164,197,252,1) 1%,rgba(79,143,249,1) 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#a4c5fc', endColorstr='#4f8ff9',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */
    min-height: 100%;
}
    @media screen and (max-width: 1024px) { /* Specific to this particular image */

body-404 {
    position: relative;
    margin: 50px auto;
    width:880px;
    text-align:center;
    color:white;
    font-family: "Helvetica Neue", "URW Palladio L", Arial, Helvetica, "Palatino Linotype";
    z-index:99;
}
于 2013-01-17T22:23:19.170 に答える
0

background-imageimage タグを使用する代わりに、 CSS プロパティを使用します。私が何を意味するかを示すために、簡単なjsfiddleを作成しました。私はそれがまさにあなたが目指しているものではないことを知っていますが、あなたの使用のためにそれをすぐに変更できるはずです. そうでない場合は、お知らせください。

于 2013-01-17T21:59:08.553 に答える