2017-02-24 92 views
0

我使用filter: blur(5px);模糊了我在身體元素中的背景圖像問題是,而不是背景圖像,div中的我的內容是受影響的。如何在CSS中模糊我的背景圖像?

enter image description here enter image description here

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title>Document</title> 
    <style> 

    body { 
     width: auto; 
     margin:0; 
     padding:0; 
     /*background-color: #2E3137; */ 
     background-image: url("images/StockSnap_Q6PIRY9O7M.jpg"); 
     background-position: center center; 
     background-repeat: no-repeat; 
     background-attachment: fixed; 
     background-size: cover; 
      -webkit-filter: blur(5px); 
     -moz-filter: blur(5px); 
     -o-filter: blur(5px); 
     -ms-filter: blur(5px); 
     filter: blur(5px); 

    } 

    @font-face { 
     font-family: 'Roboto', sans-serif; /*a name to be used later*/ 
     src: url('https://fonts.googleapis.com/css?family=Roboto'); /*URL to font*/ 
    } 

    * { 
     border-collapse: collapse; 
    } 

    h2 { 
     text-align: center; 
    } 

    .container { 
     width: 960px; 
     height: 500px; 
     margin: 50px auto; 
     position: relative; 


    } 

    .row { 
     width: 320px; 
     position: absolute; 
     top: 50%; 
     left: 50%; 
     transform: translate(-50%, -50%); 
     font-family: arial; 
     /*font-size: 13px;*/ 
     /*color: #e4e4e4; */ 
     color: white; 
     padding: 10px 55px 40px;   
     /*background: rgba(105,97,82,0.5);*/ 
     /*background: rgba(20,21,23,0.6); */ 
     background: rgb(102, 105, 110); 
     border: 1px solid white; 
     box-shadow: 0 4px 8px #000000; 
     border-radius: 5px; 
     font-family: 'Roboto'; 

    } 

    input[type=text],[type=password] { 
     width: 97%; 
     height: 30px; 
     padding-left: 5px; 
     margin-bottom: 20px; 
     margin-top: 8px; 
     color: #4f4f4f; 
     font-size: 16px; 


    } 

    #login { 
     width: 100%; 
     margin-top: 5px; 
     padding: 5px; 
     font-weight: bold; 
     cursor: pointer; 
     /* display: block; use for centering */ 
     display: block; 
     /*background-color: #DEE9FF;*/ 
    } 

    #signup { 
     width: 100%; 
     margin-top: 5px; 
     padding: 5px; 
     font-weight: bold; 
     cursor: pointer; 
    } 

    </style> 
</head> 
<body> 

<?php 
include_once("code1.php"); 
?> 

<div class="container"> 
    <div class="row"> 
     <h2> Sign In </h1> 
     <form action="p1.php" method="POST"> 
      <?php echo form_errors($errors); ?> 
      Username: <br/> 
      <input type="text" name="username" /> <br/> 
      Password: 
      <input type="password" name="password" /> <br/> 
      <input type="submit" name="submit" id="login"/> 
     </form> 

     <form action="register.php" method="POST"> 
      <input type="submit" name="register" value="Create New Account" id="signup"/> 
     </form> 
    </div> 
</div> 

</body> 
</html> 
+1

請刪除PHP和所有這些不必要的東西。 jsFiddle也會很好。 –

+0

您不能將「過濾器」應用於背景圖像......僅適用於元素或僞元素。 –

回答

1

試試這個

<div class="container"> 
    <div class="row"> 
     <h2> Sign In </h1> 
     <form action="p1.php" method="POST"> 
      <?php echo form_errors($errors); ?> 
      Username: <br/> 
      <input type="text" name="username" /> <br/> 
      Password: 
      <input type="password" name="password" /> <br/> 
      <input type="submit" name="submit" id="login"/> 
     </form> 

     <form action="register.php" method="POST"> 
      <input type="submit" name="register" value="Create New Account" id="signup"/> 
     </form> 
    </div> 
</div> 

body { 
     width: auto; 
     margin:0; 
     padding:0; 
     /*background-color: #2E3137; */ 


    } 

    body:before { 
     content: ''; 
     position: fixed; 
     width: 100vw; 
     height: 100vh; 
     background-image: url("https://wallpaperbrowse.com/media/images/background-pictures-2.jpg"); 
     background-position: center center; 
     background-repeat: no-repeat; 
     background-attachment: fixed; 
     background-size: cover; 
      -webkit-filter: blur(5px); 
     -moz-filter: blur(5px); 
     -o-filter: blur(5px); 
     -ms-filter: blur(5px); 
     filter: blur(5px); 
    } 

    @font-face { 
     font-family: 'Roboto', sans-serif; /*a name to be used later*/ 
     src: url('https://fonts.googleapis.com/css?family=Roboto'); /*URL to font*/ 
    } 

    * { 
     border-collapse: collapse; 
    } 

    h2 { 
     text-align: center; 
    } 

    .container { 
     width: 960px; 
     height: 500px; 
     margin: 50px auto; 
     position: relative; 


    } 

    .row { 
     width: 320px; 
     position: absolute; 
     top: 50%; 
     left: 50%; 
     transform: translate(-50%, -50%); 
     font-family: arial; 
     /*font-size: 13px;*/ 
     /*color: #e4e4e4; */ 
     color: white; 
     padding: 10px 55px 40px;   
     /*background: rgba(105,97,82,0.5);*/ 
     /*background: rgba(20,21,23,0.6); */ 
     background: rgb(102, 105, 110); 
     border: 1px solid white; 
     box-shadow: 0 4px 8px #000000; 
     border-radius: 5px; 
     font-family: 'Roboto'; 

    } 

    input[type=text],[type=password] { 
     width: 97%; 
     height: 30px; 
     padding-left: 5px; 
     margin-bottom: 20px; 
     margin-top: 8px; 
     color: #4f4f4f; 
     font-size: 16px; 


    } 

    #login { 
     width: 100%; 
     margin-top: 5px; 
     padding: 5px; 
     font-weight: bold; 
     cursor: pointer; 
     /* display: block; use for centering */ 
     display: block; 
     /*background-color: #DEE9FF;*/ 
    } 

    #signup { 
     width: 100%; 
     margin-top: 5px; 
     padding: 5px; 
     font-weight: bold; 
     cursor: pointer; 
    } 

現場演示 - https://jsfiddle.net/grinmax_/fmus0fe0/

+0

如何將我的背景圖像設置爲適合我的屏幕尺寸的全尺寸?看起來像我的(背景大小:封面;)是毫無意義的,因爲有寬度和高度設置爲 寬度:100vw; 身高:100vh; – studentAir01

+0

@ studentAir01在我的例子中,背景被拉伸(封面),讓我看看你在jsfidle中有什麼 – grinmax

+0

在我的情況下它不是全尺寸。我的背景圖像上方有一個白色。我在我的操作中添加了圖像。 – studentAir01

1

body:before { 
 
\t content: ''; 
 
\t position: fixed; 
 
\t width: 100vw; 
 
\t height: 100vh; 
 
\t background-image: url("http://www.planwallpaper.com/static/images/hexagons-3d-desktop-wallpaper-hd_VUiBHpV.jpg"); 
 
    background-position: center center; 
 
    background-repeat: no-repeat; 
 
    background-attachment: fixed; 
 
    background-size: cover; 
 
     -webkit-filter: blur(5px); 
 
    -moz-filter: blur(5px); 
 
    -o-filter: blur(5px); 
 
    -ms-filter: blur(5px); 
 
    filter: blur(5px); 
 
    z-index: -9; 
 
}
<body> 
 
<h1 style="margin: 20px auto; width: 80%; color: #393; background: rgba(0,0,0,0.7); text-align: center">Hello from Breakermind</h1> 
 
</body>

+0

爲什麼背景圖片沒有覆蓋整個頁面?我希望它的大小適合我的屏幕。 – studentAir01

+0

http://jsfiddle.net/jLGFp/3/ – 2017-02-24 10:52:24