I have the element <div id="pageFooter">
, and I wanted to make it full width (windows width) so I applied width:100vw
, and I didn't wanted it to be fixed/absolute. after applied it, this was the result: the div (footer, at the bottom) is moved slightly to the left.
So I searched online and I got to this Answer. I tried to apply the style and it changed nothing. How Can I fix it?
Minimal working example: (I'm using a little bit of razor, but it doesn't matter for the style. HTML:
<div class="FooterWrapper lang">
<footer class="pageFooter">
<div id="userTools" class="FooterItem">
<div class="FooterLangSwitcher">
<h4>@(Stock_WebApp_v2.Resources.AppCulture.Language)</h4>
<hr />
@foreach (string value in Stock_WebApp_v2.Resources.LanguagesAvailable.ApplicationLanguages.Split(';'))
{
<h5 onclick="loc = location.href.split('/');var cul = '@(value.Split(':')[0])';var u = loc[0] + '//' + loc[2] + '/' + cul;for (var x=4;x<loc.length;x++) {u+='/'+loc[x];} window.location.replace(u);">@(value.Split(':')[1])</h5>
}
</div>
</div>
</footer>
</div>
CSS:
.FooterWrapper {
width: 100vw;
}
.FooterItem {
color:white;
margin: 5px 5px 5px 5px;
padding: 5px 5px 5px 5px;
}
body {
font-family: Arial, sans-serif;
}
add margin 0
on body
body {
font-family: Arial, sans-serif;
margin:0;
}
In your case you should apply body { margin:0;}
.
To make full width or height an element and fit with screens you need must follow following steps to avoid unexpected situation:
html,body { padding:0; margin:0;}
html,body { padding:0; margin:0;}
box-sizing: border-box;
"top/right/bottom/left:-50px
".Browsers default style may include automatic margins set to your element's parent(s) which will be added to the whole viewport width thus causing the overflow. You can try to reset the default margin set on an element by adding the CSS rule :
margin: 0;
or by inlining the style attribute directly on your element :
<div style="margin:0;"></div>
EG - resetting margins on the parent body element :
.FooterWrapper { width: 100vw; } .FooterItem { color: white; margin: 5px 5px 5px 5px; padding: 5px 5px 5px 5px; } body { font-family: Arial, sans-serif; /* Set body's margin to 0 to ovverride browser defaults */ margin: 0; }
<div class="FooterWrapper lang"> <footer class="pageFooter"> <div id="userTools" class="FooterItem"> <div class="FooterLangSwitcher"> <h4>@(Stock_WebApp_v2.Resources.AppCulture.Language)</h4> <hr /> @foreach (string value in Stock_WebApp_v2.Resources.LanguagesAvailable.ApplicationLanguages.Split(';')) { <h5 onclick="loc = location.href.split('/');var cul = '@(value.Split(':')[0])';var u = loc[0] + '//' + loc[2] + '/' + cul;for (var x=4;x<loc.length;x++) {u+='/'+loc[x];} window.location.replace(u);">@(value.Split(':')[1])</h5> } </div> </div> </footer> </div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.