28
I’m trying to make a header that should fill the entire page width, but leaving a 5px gap on each side. For example:
| ::::::::::::::: |
| ::::::::::::::: |
In this case the Pipes are the maximum page width and the two dots are one <div>
that should occupy that space, so that when the browser window is resized it still occupies that whole range, leaving 5px gaps on both sides.
This is what I tried to do:
#header {
height: 70px;
width: 100%;
margin-top: -10px;
margin-bottom: 5px;
padding-right: 5px;
padding-left: 5px;
background-color: gray;
border-radius: 0px 0px 10px 10px;
position: fixed;
z-index: 1;
}
But that was the result:
As you can see he ignored the gaps on the right and left, because when I remove the lines below it is the same way.
padding-right: 5px;
padding-left: 5px;
What I do?
HTML code of the page:
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
<title></title>
</head>
<body>
<div id="header"></div>
<div class="left"></div>
<div class="right"></div>
<div id="footer"></div>
</body>
</html>
The CSS code:
#header {
height: 70px;
width: 100%;
margin-top: -10px;
margin-bottom: 5px;
margin-right: 50px;
margin-left: 50px;
background-color: gray;
border-radius: 0px 0px 10px 10px;
position: fixed;
z-index: 1;
}
.left {
display: inline-block;
height: 700px;
width: 10%;
margin-top: 65px;
background-color: gray;
border-radius: 5px;
float: left;
}
.right {
display: inline-block;
height: 700px;
width: 89%;
margin-top: 65px;
margin-bottom: 5px;
background-color: gray;
border-radius: 5px;
float: right;
}
#footer {
height: 70px;
background-color: gray;
border-radius: 5px;
clear: both;
}
The
position:fixed
is it really a requirement? That is, you want the header not to scroll with the rest of the page? If so, Voc6e already has two correct answers. If I can give upposition:fixed
, there are simpler solutions.– bfavaretto