To create a header, you have multiple options in CSS. You can utilize the :before
or :after
pseudo-elements to add content before or after an element.
For example, you can use the following HTML:
<header></header>
And apply the following CSS styling to it:
header{
border:3px solid;
height:300px;
position:relative;
}
header:before{
content:'Header';
position:absolute;
top:-10px;
left:50px;
background:#fff;
padding:0 20px;
}
Another method is to use both the header
and h1
elements together. Here's an example:
html:
<header><h1>Header</h1></header>
With the corresponding CSS:
header{
border:3px solid;
height:300px;
position:relative;
}
header > h1{
position:absolute;
top:-35px;
left:50px;
background:#fff;
padding:0 20px;
}
Alternatively, you could simplify things even further by using the fieldset
element for your header. See below for an example:
<fieldset>
<legend>Header</legend>
</fieldset>