0

I have fixed header, and I want to do this: enter image description here

I don't have any idea. Does somebody have experience with it?

<div class="header">
    Nejaka hlavicka s rozmazanym pozadim
</div>
<div class="body">
  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>

.header {
  background: rgba(0,0,0,.1);
  padding: 20px;
  position: fixed;
}
.body {
  font-weight: bold;
}

jsfiddle

Stalky
  • 121
  • 6

3 Answers3

1

The simplest solution is to apply the same image as a background to an element (or pseudo-element as I have here) and blur that. The pseudo-element is then positioned (absolutely) in such a way as it forms the background of the header itself.

Codepen Demo

* {
  margin: 0;
  position: relative;
}
body {
  background-image: url(http://www.wallpaperawesome.com/wallpapers-awesome/wallpapers-for-monitor-4-3-almost-square-awesome/wallpaper-for-monitor-4-3-almost-square-awesome-948.jpg);
}
header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2em;
  height: 50vh;
  color: white;
  background-color: rgba(255, 255, 255, 0.15);
}
header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  background-image: url(http://www.wallpaperawesome.com/wallpapers-awesome/wallpapers-for-monitor-4-3-almost-square-awesome/wallpaper-for-monitor-4-3-almost-square-awesome-948.jpg);
  filter: blur(10px);
  opacity: 1;
  z-index: -1;
}
<header>
  <h2>MY TEXT HERE</h2>
</header>
Paulie_D
  • 107,962
  • 13
  • 142
  • 161
0

The question is already older but for those who find it: in the current CSS3 you are able to use

backdrop-filter: brightness(110%) blur(6px);

for example. With some additional settings like brightness() you can ensure that the text in front has the necessary contrast ratio. You can simply add it to your .head{}.

*,
*:before,
*:after {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}

body {
  color: #fff;
  font-weight: bold;
  background: rgb(20, 27, 43);
  background-image: url(https://pixnio.com/free-images/2017/10/30/2017-10-30-14-24-49.jpg);
  
  background-size: cover;
  background-repeat: no-repeat;
  background-position: 0 0;
  height: 100vh;
  width: 100vw;
}

header {
  width: 100vw;
  top: 0;
  background: rgba(0, 0, 0, .1);
  padding: 20px;
  max-height: 60px;
  position: fixed;
  backdrop-filter: brightness(70%) blur(5px);
  z-index: 10;
}

main {
  margin: 80px 20vw 0 20vw;
  width: 100%;
  max-width: 500px;
  border-radius: 10px;
  padding: 10px;
  backdrop-filter: brightness(50%) blur(5px);
}
<body>
  <header>
    Nejaka hlavicka s rozmazanym pozadim
  </header>
  <main>
    <section>
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. <br>
      Aliquam corporis cumque distinctio, eaque in iste iure labore maxime nesciunt nostrum perferendis quidem rem sapiente, sunt tempore. <br>
      Consequatur distinctio eos placeat!
    </section>
  </main>
</body>
Benedict Lang
  • 103
  • 1
  • 4
-1

Do you mean 'z-index'?

.header {
  background: green;
  padding: 20px;
  position: fixed;
  z-index: 10;
}
.body {
  font-weight: bold;
}
<div class="header">
  Nejaka hlavicka s rozmazanym pozadim
</div>
<div class="body">
  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>
  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>  text a spousta dalsiho textu <br>
</div>

I don't understand your question

  • I need header with opacity background: For example `background: rgba(0,0,0,.2)` and content, which is under header must be blurred. Something like this: [link](https://postimg.org/image/fj9sgzumh/) – Stalky Oct 30 '16 at 10:29