Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a transparent-sticky header?

I want to try to code a fixed-header that is a bit transparent.

Any ideas, sample code, tutorials? I want to achieve it with CSS only, if possible. Playing with the opacity (CSS3) is needed, I guess.

like image 895
Andreas Litis Avatar asked Oct 23 '11 19:10

Andreas Litis


People also ask

How do I make a header transparent in HTML?

You can try to add transition for #header element via changing of the opacity value (just for example). Or you can change top value: when header is visible -> top: 0 , and when header is hidden -> top: -100px (example value, should be equal or more then header height). Save this answer. Show activity on this post.

How do I make the header in an Elementor header and footer transparent?

Step 1: create a header the same way you usually do — don't forget that it needs to be sticky. Step 2: don't choose the background for the part where the header is (setting the rgba to 255,255,255,0 or 0,0,0,0 can also be used to set the background to transparent). Step 3: publish the header as you normally would.


2 Answers

Example

Full screen jsFiddle: http://fiddle.jshell.net/NathanJohnson/LrNBt/show/

jsFiddle: http://jsfiddle.net/NathanJohnson/LrNBt/

Code

HTML:

<div id="header">
    <div id="header-content">
        <h1>Here is some heading text :)</h1>
        <p>Here is some more content of the header...</p>
    </div>
</div>

CSS:

body {
    font-family: arial, sans-serif;
    padding: 0;
    margin: 0;
}
#header {
    background-color: black;
    /*Opacity start*/
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
    filter: alpha(opacity=80);
    -moz-opacity: 0.80;
    -khtml-opacity: 0.8;
    opacity: 0.8;
    /*Opacity end*/
    color: white;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 150px;
    padding: 0;
    margin: 0;
}
#header #header-content {
    margin: 10px;
}

Or, you could just use rgba() instead of opacity:

#header {
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 150px;
    padding: 0;
    margin: 0;
}
#header #header-content {
    margin: 10px;
}

I hope this helps.

like image 99
Nathan Avatar answered Oct 19 '22 22:10

Nathan


Use Firebug to analyze their code:

#header {
    left: 0;
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 90;
    background: url("../images/bg-header.png") repeat-x scroll 0 0 transparent;
    height: 247px;
}

Instead of using an image use:

background: #000;
filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
like image 37
StuR Avatar answered Oct 20 '22 00:10

StuR