You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用HTML/CSS实现图片按钮对齐时,最右侧按钮错位问题求助

Fixing Your Misaligned Image Button Issue

Hey there! Let's get that last button aligned properly. After checking your code, I found a few straightforward issues that are causing the misalignment:

  • Unclosed HTML Tag: Your third .column div isn't closed, which means the fourth column is nested inside it instead of being a sibling element. That's the biggest reason for the misalignment.
  • Incorrect Image Width: The last image has style="width:200%;" set, which makes it way larger than its container and throws off the layout.
  • Style Conflicts & Typos:
    • You have both a CSS rule setting body { background: url('realheckindoggopupper.png') } and an inline style="background-color:black" on the body tag—pick one to avoid confusion.
    • text-size isn't a valid CSS property; you want font-size for your <h1>.
    • The <br> tag doesn't need a closing </br> (it's self-closing in HTML: <br/> or just <br>).

Corrected HTML & CSS

* { box-sizing: border-box; }
body { 
  background: url('realheckindoggopupper.png');
  background-color: black; /* Fallback if image doesn't load */
  margin: 0; /* Remove default body margin to avoid extra space */
}
div { padding: 5px; background-color: black; box-sizing: border-box; }
.column { float: left; width: 25%; padding: 1px; }
.row::after { content: ""; clear: both; display: table; }
<body>
  <div>
    <h1 style="color:blue;font-size:50px;">Welcome to the Mamiya Mansion!</h1>
    <p style="color:white;"> This is a place where I put all my thoughts. I talk about all my different interests here, from retrogaming, to retro-anime, linguistics, and philosophy. I don't have much here yet, more is on the way (including better CSS!), <br> but these buttons will allow you to access different parts I'm working on. </p>
  </div>
  <div class="row">
    <div class="column">
      <a href="retrostuff.html">
        <img src="retrostuff.png" style="width:100%;">
      </a>
    </div>
    <div class="column">
      <a href="creations.html">
        <img src="creations.png" style="width:100%;">
      </a>
    </div>
    <div class="column">
      <a href="pseudstuff.html">
        <img src="pseudstuff.png" style="width:100%;">
      </a>
    </div> <!-- Fixed: closed this column div -->
    <div class="column">
      <a href="misc.html">
        <img src="misc.png" style="width:100%;"> <!-- Fixed: changed to 100% width -->
      </a>
    </div>
  </div>
</body>

A quick breakdown of the fixes:

  • Closed the third .column div so all four columns are properly side-by-side in the .row
  • Set the last image's width to 100% to match the others
  • Fixed the font-size typo on the heading
  • Cleaned up the <br> tag and removed the redundant inline body background color (added a fallback in CSS instead)
  • Added margin:0 to the body to eliminate default browser spacing that might cause unexpected layout shifts

内容的提问来源于stack exchange,提问作者Blauheim44

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 10:32:27