如何设置CSS动画:淡入onload,但bgimg将保持不透明

时间:2018-04-17 15:05:02

标签: html css

使用以下代码,我可以制作一个动画,在淡入时加载页面,但我希望能够制作动画,使我的背景图像保持不透明。

有问题的网页是一个虚拟登录表单,用于学校项目。

 <html>
   <div id="transparent"><div id="bg"> <body>
  <style>
html {
padding: 0;
margin: 0;
width: 100%;
height: 100%;
 }
 body {
   padding: 0;
   margin: 0;
   width: 100%;
   height: 100%;
   }



input[type=text], select {
    width: 100%;
    padding: 14px 20px;
    margin: 8px 0;
    display: inline-block;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
}

input[type=password], select {
    width: 100%;
    padding: 14px 20px;
    margin: 8px 0;
    display: inline-block;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
}
input[type=submit] {
    width: 45%;
    background-color: #1a1aff;
    color: white;
    padding: 14px 20px;
    margin: 8px 0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

input[type=submit]:hover {
    background-color: #0000e6;
}

input[type=reset] {
    width: 45%;
    background-color: red;
    color: white;
    padding: 14px 20px;
    margin: 8px 0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

input[type=reset]:hover {
    background-color: #e60000;
}
div.inner {
    background-color: #f1f3f2;
    padding: 30px;
    width: 400px;
}
#tail{
    position: absolute;
    }

#bg {
    width: 100%;
    height: 100%;
    background: url('backgroundimg.jpg') no-repeat center center fixed;

    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;

    -webkit-animation: myfirst 5s ;
    animation: myfirst 5s ;
  }

  @-webkit-keyframes myfirst {
    from {opacity: 0.2;}
    to {opacity: 1;}
  }
  @keyframes myfirst {
    from {opacity: 0.2;}
    to {opacity: 1;}
  }

#transparent {
  width: 100%;
  height: 100%;
  display: block;
  position: relative;
}

#transparent::after {
  content: "";
  background: url(backgroundimg.jpg);
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center center;
  opacity: 0.1;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  position: absolute;
  z-index: -1;   
}
   </style>

HTML:

 <div class=inner><div class=border>
<div class=login align=left>
<div id="tail">
<p>Welcome!</p>
<p></p></div>
<font size=13 face=helvetica> Log In</div> </font><br>
    <form name="myForm">
    <font face=helvetica size=6>
    <input type="text" placeholder="Username" id="fname" size=30 name="fname" required> <br> 
    <input type="password" placeholder="Password" id="pword" name="pword" required> <br> <br> 

        <input type=submit onClick="myFunctions(); return false" id="button" value="OK">

        <input type=reset value="CANCEL">
    </form> </div></div></div>

在此先感谢,任何帮助将不胜感激!

0 个答案:

没有答案