Reputation: 341
i have the following code but for some reason does not work.
<body>
<div class="body_wrapper">
<header></header>
</div>
</body>
i would like body_wrapper to have margin:20px but when put position:fixed to header ignores it from the right side.
i want header take width 100% of the body_wrapper. i tried putting right:20px, right:20px but nothing
is this possible without putting for example width:98%?
Upvotes: 1
Views: 5683
Reputation: 123397
remove the width
and set both left
and right
properties
e.g. http://jsfiddle.net/rbk7jv8b/
header {
min-height:160px;
background:red;
position:fixed;
left: 20px;
right: 20px;
z-index:100;
}
Another approach is using calc()
for the width
property (100%
minus 40px
of margin)
e.g. http://jsfiddle.net/f1ay8zkr/
header {
min-height:160px;
background:red;
position:fixed;
width: calc(100% - 40px);
z-index:100;
}
Upvotes: 4
Reputation: 1538
add right:20px;
and left:20px;
the remove width:100%
header {
min-height: 160px;
background: red;
position: fixed;
z-index: 100;
right: 20px;
left: 20px;
}
Upvotes: 0
Reputation: 1538
Your div isn't close.
<body>
<div class="body_wrapper">
<header></header>
</div>
</body>
Then, use left and right properties :
header {
min-height:160px;
background:red;
position:fixed;
left: 20px;
right: 20px;
}
Upvotes: 0