渐变满刻度的背景CSS [英] Gradient full scale background CSS

查看:114
本文介绍了渐变满刻度的背景CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我试图让我的背景是一个渐变,始终是100%的宽度和高度,和它的作品,除了事实,什么都不会出现在它的上面。这里是code我现在有。

Alright so I am trying to make my background be a gradient that is always 100% width and height, and it works, except for the fact that nothing will show up on top of it. Here is the code I currently have.

<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>

DEMO:

http://mysteriousorigin.com/missing.html

推荐答案

它通常被认为是不良的做法有空元素喜欢你的 #bodyBg 。只要把背景渐变的HTML(或机构)元素,摆脱了无用的div:

It's generally considered poor practice to have empty elements like your #bodyBg. Just put the background gradient on the html (or body) element and get rid of the useless 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;
}

这篇关于渐变满刻度的背景CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆