duanchun6148 2012-04-12 22:23
浏览 79
已采纳

页面顶部的奇怪空白 - HTML,CSS和PHP

Alright, this is a weird problem I'm having. I have two pages, which are slightly different, but that share several of the same elements (two images, basically).

These images are both controlled by the same CSS style sheet, however, they both seem to be about 20-30 pixels lower on the second page.

The second page is different in the fact that it uses PHP before the Doctype Declaration. However, as said later on, I don't think this is the problem.

To see this effect, look at both of these pages consecutively: http://www.codecreek.biz/login and http://www.codecreek.biz/registration/register.

Just to be clear, I've looked at many possible answers on this already. This doesn't appear to be my case, as I'm not using a table on these pages.

Here's what I've tried:

  • Checking for whitespace in the code. However, if you view the sources for both of these pages, you'll actually notice that the second, problematic one has one less line of whitespace at the top, before its Doctype Declaration.
  • Removing the PHP code from the second page. This didn't have any effect either.
  • Reducing the apparent space between the closing PHP tag ?> and the <!DOCTYPE HTML> to nothing. This again didn't have any effect.
  • Checking for a BOM. I did this using vim, and the results confirmed that no BOM was used.
  • Checking my CSS. I didn't find anything strange, but I'm quite a novice at CSS, so, as this might be the problem, here's the link to my style sheet: http://www.codecreek.biz/resources/main.css. (Disclaimer: I'm in the process of rewriting that page, so if it looks quite strange, there you go !).

Additionally, Safari's developer inspection tool clearly shows that the <body> tag on my second page only begins around 20 pixels down.

I'm honestly quite lost. I'm hoping there is a simple fix for this, but I've been working on this for several hours to no avail.

EDIT: Here's the CSS, both for the 'title' image, and the 'squiggly line' image.

#login_title { position:absolute; width:1000px; top:100px; }
#login_line { position:absolute; width:500px; top:330px; left:250px; }
  • 写回答

3条回答 默认 最新

  • douzha6055 2012-04-12 22:29
    关注

    The H1 on the register page has a default Margin to it. Sometimes, I don't know why, if you give the first element a margin, it applies it to the parent.

    By giving the H1 #register_title a top margin of 0, you should fix your problem.

    #register_title { margin-top: 0; }
    

    Always remember to use a reset.css implementation or keep in mind that elements are styled by default.

    Edit: I'd like to point out that this was an issue because of all your previous elements were absolutely positioned. You really should not be using absolute positioning the way you are. You should use margin-top, padding-top to move elements down the page. Absolute positioning should only be used when no other avenues of positioning an element are available.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向