Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a CSS background that is all white with a 100px blue bar at the very top of the page?

Tags:

css

I see a lot of code dealing with percentages, but what if I just wanted a 100px bar in the top? I am only able to edit the CSS of this page, so can I do it without any use of HTML?

like image 374
lfkwtz Avatar asked Dec 19 '22 09:12

lfkwtz


2 Answers

Use :before pseudo-element:

body:before {
    content: " ";
    display:block;
    width:100%;
    height:100px;
    background:blue;
}

With this you can change some properties and have this results:

Content Above the Bar

body {
  color:white;
  margin:0;
}
body:before {
    content: " ";
    display:block;
    position:absolute;
    top:0;
    width:100%;
    height:100px;
    background:blue;
    z-index:-1;
}
<h1>The content will be above the bar</h1>

Content Under the Bar

body {
  margin:0;
}
body:before {
    content: " ";
    display:block;
    width:100%;
    height:100px;
    background:blue;
}
<h1>The content will be under the bar</h1>
like image 115
DaniP Avatar answered Jan 11 '23 23:01

DaniP


You can use a sized, laterally-repeating, linear-gradient:

html {
    background: white linear-gradient( 0, blue, blue ) repeat-x;
    background-size: 100px 100px;
}

Fiddle: http://jsfiddle.net/r5a2uabw/4/

like image 38
Sampson Avatar answered Jan 12 '23 01:01

Sampson