简体   繁体   English

网站底部的空白

[英]White space at bottom of site

I am trying to eliminate this white space at the bottom of my upcoming portfolio site: http://codymiracle.com/ 我正在尝试消除即将到来的投资组合网站底部的空白: http : //codymiracle.com/

What occurs is the footer seems to either be too long or too short on -most- monitors. 发生的是,大多数显示器上的页脚似乎太长或太短。 Either I get a scroll on really tiny windows, or more commonly larger resolutions produce a small bit of white space that I can't seem to get rid of. 我要么在很小的窗户上滚动,要么更常见的是较大的分辨率会产生少量的空白,而这似乎是我无法摆脱的。

Feel free to use the view page source etc to view my CSS and HTML. 随意使用查看页面源代码等来查看我的CSS和HTML。 I'm not a web designer at heart, only taken one class and this is pieced together slowly. 我并不是一个真正的网页设计师,只上了一堂课,而且课程进展缓慢。 Please let me know if you have found anything that could fix it. 如果您发现任何可以解决的问题,请告诉我。

Things I've tried: 我尝试过的事情:

  • adding height: 100% to my body 增加身高:100%我的身体
  • adding overflow: hidden to my contentFooter 添加溢出:隐藏到我的contentFooter
  • adding overflow: hidden!important to my contentFooter 添加溢出:隐藏!对我的内容很重要

I had white space at the bottom of all my websites; 我所有网站的底部都有空白; this is how I solved the matter: 这是我解决问题的方法:

The first and best thing you can do when you are debugging CSS issues like this is to add: 调试CSS问题时,您要做的第一件事也是最好的事情是添加:

* { border: 1px solid red; }

This CSS line puts a red box around all your HTML elements. 此CSS行在所有HTML元素周围放置一个红色框。

I had white space at the bottom of my page due to a faulty Chrome extension which was adding the div #dp_swf_engine to the bottom of my page: 由于错误的Chrome扩展程序将div #dp_swf_engine添加到页面底部,因此页面底部有#dp_swf_engine

<div id="dp_swf_engine" style="position: absolute; width: 1px; height: 1px;"></div>

Without the red box, I would have never noticed a 1px div. 没有红色框,我将永远不会注意到1px的div。 I then got rid of the faulty extension, and put display:none on #dp_swf_engine as a secondary measure. 然后,我摆脱了错误的扩展名,并将display:none放在#dp_swf_engine作为辅助措施。 (Who knows when it could come back to add random white space at the bottom of my page for all my pages and apps?!) (谁知道什么时候可以回来在我的页面底部为所有页面和应用添加随机空白?!)

I could not find any white space at the bottom of the page. 我在页面底部找不到空白。 Though there was some extra space in the footer. 尽管页脚中有一些额外的空间。 if that is what you are referring to then you can use this to remove the extra space. 如果那是您要指的,那么您可以使用它来删除多余的空间。

#contentFooter
{
    height:auto;
    background-color: #9db0ae;

}

The extra space is because of the fixed height of the footer. 多余的空间是因为页脚的高度固定。 Setting to height to auto should solve the issue. height设置为auto应该可以解决此问题。

在此处输入图片说明

Side note: I'm testing in Maxthon. 旁注:我正在Maxthon中进行测试。

Firstly, your div#background doesn't take up the whole page, instead taking up the least space it can, and as the footer is inside it, it can't extend beyond this. 首先,您的div#background不会占用整个页面,而是会占用尽可能少的空间,并且由于页脚位于其中,因此它不能超出此范围。 To fix this, I chose to add 为了解决这个问题,我选择添加

div#background {
    position: absolute;
    height: 100%;
    width:  100%;
}

I then modified the footer as well to stay at the bottom of its parent. 然后,我还修改了页脚,使其停留在其父级的底部。 Because its parent is absolutely positioned, I can use the easy method of: 由于其父对象是绝对位置,因此我可以使用以下简单方法:

div#contentFooter {
    position: absolute;
    width:  100%;
    bottom:  0px;
}

Finally, I moved the <hr> tag inside of the footer so that it stayed with it. 最后,我将<hr>标记移到了页脚内部,使其与之保持一致。 I'd normally just use a top border, but this didn't have quite the same look. 我通常只使用顶部边框,但是外观并不完全相同。 The page now looks like this. 该页面现在看起来像这样。

PS. PS。 You will have clipping issues at the bottom of the page if the window is too small, but they would occur anyway because the div#contentBarrier has min-height less than div#background . 如果窗口太小,您将在页面底部出现剪切问题,但是无论如何它们都会发生,因为div#contentBarrier min-height小于div#background

I don't see any "white space" at the bottom of your site if by "white space" you mean "space that is white." 如果您用“空白”表示“白色空间”,则在网站底部看不到任何“空白”。 What browser are you using? 你使用的是什么浏览器? Perhaps a browser extension is modifying your page client-side. 也许浏览器扩展正在修改您的页面客户端。 You may also consider using something like Browsershots to check the extent of your problem. 您也可以考虑使用Browsershots之类的方法来检查问题的程度。

If you're referring to the space within your footer, you'll need to change the height defined in this CSS declaration: 如果要引用页脚中的空间,则需要更改此CSS声明中定义的高度:

#contentFooter {
    height: 42px; /* change this number */
}

EDIT: Working on getting you a footer attached to the bottom... 编辑:正在努力使您将页脚附加到底部...

Try setting: 尝试设置:

#contentFooter {
   height: 42px;
   background-color: #9db0ae;
   position: fixed;
   bottom: 0;
   width: 100%;
}

#contentBarrier {
   clear: both;
   width: 1200px;
   padding-top: 20px;
   text-align: center;
   height: 100%;
}

Also move your orange hr into your footer. 还要将橙色hr移到页脚中。 Or, better yet, switch to using CSS borders. 或者,更好的是,切换到使用CSS边框。

With a little tweaking, that should do it. 稍作调整,就可以做到。 Your footer would sit at the bottom of the screen no matter the height of the page. 无论页面的高度如何,您的页脚都将位于屏幕底部。 If the screen is smaller than the height of your page, content would scroll from under the footer. 如果屏幕小于页面的高度,则内容将从页脚下方滚动。 You might have to add some margin to the bottom of your content block to ensure that no content ever gets stuck under the footer. 您可能必须在内容块的底部添加一些边距,以确保没有任何内容卡在页脚下。

Your page layout is 905 pixels high, so it will only fit exactly if the browser window happens to be exactly that high. 您的页面布局高905像素,因此仅在浏览器窗口恰好那么高时才完全适合。 That might happen with a specific resolution with a specific operating system and a specific browser, but for most people it won't be. 对于特定的分辨率,特定的操作系统和特定的浏览器,可能会发生这种情况,但是对于大多数人而言,情况并非如此。

You can make the body element take up the full height of the browser by adding this to the CSS: 通过将其添加到CSS,可以使body元素占据浏览器的整个高度:

html, body { height: 100%; }

Then you can place the footer at the bottom of the body element, and add padding the content so that scrolling works as expected when the window is smaller: 然后,您可以将页脚放在body元素的底部,并添加内容的填充,以便在窗口较小时可以按预期进行滚动:

#contentBarrier { padding-bottom: 45px; }
#background > hr { position: absolute; width: 100%; bottom: 42px; }
#contentFooter { position: absolute; width: 100%; bottom: 0; }

对于遇到此问题但不知道该怎么办的其他人,或者上述答案没有回答您的问题:

body {max-height: 100%;}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM