简体   繁体   English

如何删除网页底部的空白?

[英]How can I remove the white space at the bottom of my web pages?

I'm trying to create a site using Wordpress. 我正在尝试使用Wordpress创建一个网站。 I created a theme and most of my pages are created using page templates because I wanted to stay away from the blog look. 我创建了一个主题,并且我的大多数页面都是使用页面模板创建的,因为我想远离博客外观。

Everything looked great until I viewed the site on my ipad in portrait mode. 在我以纵向模式在ipad上查看该网站之前,一切看起来都很不错。 I have a huge white space at the bottom of every page. 每页底部都有空白。 I used Chrome Canary's developer's tool but could not find the element that's causing the whit space. 我使用了Chrome Canary开发人员的工具,但找不到导致丝毫空间的元素。

I've been searching forums for days and tried solutions that have helped others with the problem. 我在论坛上搜索了几天,并尝试了可以​​帮助其他人解决该问题的解决方案。 No luck so far. 到目前为止没有运气。

I tried using media queries like: 我尝试使用类似以下的媒体查询:

 @media only screen and (min-width: 768px) and (max-device-width: 1024px) and      (orientation:portrait)   and (-webkit-min-device-pixel-ratio: 1) {

 Html,body{
     Overflow:hidden;
 }

Still have the huge white space at the bottom of every page when I'm in portrait mode on my ipad. 当我在ipad上处于纵向模式时,每页底部仍有巨大的空白。

Please help me find the fix for this problem. 请帮助我找到解决此问题的方法。 Here's a link to my site: http://www.davidsdrift.com/ 这是指向我的网站的链接: http : //www.davidsdrift.com/

Thanks for any help. 谢谢你的帮助。

If your site design has a static height, then any browser that is taller than that height (most mobile browsers, since they're in portrait orientation) will just stop at that point, and not put anything else below. 如果您的网站设计具有静态高度,则任何高于该高度的浏览器(大多数移动浏览器,因为它们都是纵向的)都只会在该点停止,而不会在下方放置其他任何内容。 The browser just defaults to "nothing" (ie white space) after that. 在那之后,浏览器仅默认为“无”(即空白)。

You could set a simple background color, so that it's not just defaulting to white below your designed area ( body {background-color: #CCCCCC;} ), or try something fancier than that. 您可以设置一个简单的背景颜色,这样它不仅可以在设计区域( body {background-color: #CCCCCC;} )下默认不为白色,还可以尝试一些更漂亮的body {background-color: #CCCCCC;}

Or, (gulp) you could totally re-jigger the site to not use a static rectangular design. 或者,(吞咽)您可以完全重新调整站点的位置,以不使用静态矩形设计。

It depends if you want to put image to fill 100% your height just add 这取决于您是否要将图像填充为高度的100%,只需添加

background-size: 100% 100%;

Else if you want to fill content use percentage not pixels for full height 否则,如果要填充内容,请使用百分比而不是像素来表示全高

Remove the two background-size properties from body and add background-size: cover; body删除两个background-size属性,然后添加background-size: cover; .

Add this selector 添加此选择器

html {
    min-height: 100%;
}

Your background should now cover the entire screen regardless of resolution. 现在,无论分辨率如何,背景都应覆盖整个屏幕。 You may also wish to add background-position: center center; 您可能还希望添加background-position: center center; too. 太。

Example

html {
    min-height: 100%
}
body {
    background: url(images/homePage.jpg);
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center center;
}

To add to Joe's answer: The reason why you are seeing white space on the ipad in portrait mode is because of the aspect ratio and orientation of your background image. 补充一下乔的答案:之所以以纵向模式在ipad上看到空白是因为背景图像的长宽比方向

There are countless fixes for this, however they all depend on what you would like to do with that extra white space. 对此有无数修复程序,但是它们全都取决于您要如何使用额外的空白。 You could enlarge your background to cover the whole space, repeat the background, use CSS3 properties to create a mirror effect, etc. 您可以放大背景以覆盖整个空间,重复背景,使用CSS3属性创建镜像效果,等等。

Assuming you just want the background to take up the whole space when in portrait mode use this: 假设您只希望背景在纵向模式下占据整个空间,请使用以下命令:

@media (orientation:portrait){
  html{ min-height:100% }
  body {
    background:url(images/homePage.jpg);
    background-repeat:no-repeat;
    background-size:cover;
    background-position:center center
  }
}

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

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